/***************************************************************** Author:lbn187, a konjac TwT Date:2016-03-12 Contest:Bestcoder Algorithm:QAQ ^_^ Orz hzh, NOI gold members, IOI 2016 world champion ^=^ Orz hhw, you are our blue moon, with you will live ^~^ Orz mxh, you are our red sun, without you we'll die ^-^ Orz yizhou, I wish you a successful marriage ^w^ Orz xianyangyu, you can sleep all the time in the game *****************************************************************/ #pragma comment(linker, "/STACK:1024000000,1024000000") #include #include #include #include #include #include #include #include #define fo(i,n) for(int i=0;i=0;i--) #define rep(i,a,n) for(int i=a;i<=n;i++) #define per(i,a,n) for(int i=n;i>=a;i--) #define mjj(i,x) for(int i=fir[x];i;i=ne[i]) #define X first #define Y second #define MAX(a,b) a=max(a,b) #define MIN(a,b) a=min(a,b) #define mp make_pair #define gi(a) scanf("%d",&a); #define gi2(a,b) scanf("%d%d",&a,&b); #define gi3(a,b,c) scanf("%d%d%d",&a,&b,&c); #define gl(a) scanf("%I64d",&a); #define gs(s) scanf("%s",s); #define wi(a) printf("%d\n",a); #define wi2(a,b) printf("%d %d\n",a,b); #define wl(a) printf("%I64d\n",a); #define spr(x) (x*x) #define pi acos(-1) #define CM(a,b) memcpy(a,b,sizeof(b)) #define CL(a) memset(a,0,sizeof(a)) #define N 444 #define M 444444 #define inf 1e9 #define eps 1e-8 using namespace std; int n,m,W,S,T,p,x,y,k,i,j,P,Q,fl,wl,tot,sum,ans,h,t,fir[N],va[M],la[M],ne[M],co[M],q[N],d[N],fa[N],pre[N];bool v[N]; void ins(int x,int y,int fl,int z){ la[++tot]=y;ne[tot]=fir[x];va[tot]=fl;co[tot]=z;fir[x]=tot; la[++tot]=x;ne[tot]=fir[y];va[tot]=0;co[tot]=-z;fir[y]=tot; } bool spfa(){ for(i=1;i<=T;i++)d[i]=1e9; for(memset(v,0,sizeof(v)),d[S]=h=0,v[q[t=1]=S]=1;h^t;) for(i=fir[x=q[h=h%T+1]],v[x]=0;i;i=ne[i]) if(d[x]+co[i]