#include #include #include #include #define clr(x)memset(x,0,sizeof(x)) #define min(a,b)(a)<(b)?(a):(b) const int INF=INT_MAX; const int maxn=800; const int maxm=1000000; struct node { int from,to,next,c; }e[maxm]; int tot; int head[maxn]; void add(int s,int u,int f1,int f2) { e[tot].from=s; e[tot].to=u; e[tot].c=f1; e[tot].next=head[s]; head[s]=tot++; e[tot].from=u; e[tot].to=s; e[tot].c=f2; e[tot].next=head[u]; head[u]=tot++; } int q[maxn]; int cnt[maxn]; int d[maxn]; int low[maxn]; int cur[maxn]; int maxflow(int s,int t,int n) { int *front=q,*rear=q; for(int i=0;i0) { d[e[i].to]=d[v]+1; cnt[n]--; cnt[d[e[i].to]]++; *rear++=e[i].to; } } } int flow=0, u=s, top=0; low[0]=INF; for(int i=0;i0&&d[u]==d[e[i].to]+1) { low[top+1]=min(low[top],e[i].c); q[++top]=i; u=e[i].to; break; } } if(i!=-1) { if(u==t) { int minf=low[top]; for(int p=1,i;p<=top;++p) { i=q[p]; e[i].c-=minf; e[i^1].c+=minf; } flow+=minf; u=s; low[0]=INF; top=0; } } else { int old_du=d[u]; cnt[old_du]--; d[u]=n-1; for(int i=head[u];i!=-1;i=e[i].next) if(e[i].c>0&&d[u]>d[e[i].to]) d[u]=d[e[i].to]; cnt[++d[u]]++; if(d[u]>1; if(ok(mid,s,t,n)){ res = mid; l = mid+1; } else r = mid-1; } printf("%d\n",res); } return 0; }