/* * =template=.cpp * Copyright (C) 2017 hzw * * Distributed under terms of the MIT license. */ #include #include #include #include #include #include #include #include #include #include #include #define FR first #define SC second #define MP make_pair #define rep(i,a,b) for (int i=a;i<=b;i++) #define pb push_back #define ws wss using namespace std; typedef long long LL; typedef pair PII; template void upmax(T &a,T b) { if (a void upmin(T &a,T b) { if (a>b) a=b;} void read(int &x) { char ch;int fu=1; while ((ch=getchar())<=32); x=0; if (ch=='-') fu=-1;else x=ch-48; while ((ch=getchar())>32) x=x*10+ch-48; x*=fu; } const double pi=acos(-1); void upmax(int &a,int b) { if (ab) a=b;} //----------------------- const int N=5010; struct Edge{int y,z,ne;}; int n,m,k,cas, num; Edge e[N];int last[N]; int x[10],y[10],z[10]; int S,T,c[1000]; void add(int x,int y,int z) { e[++num]=(Edge){y,z,last[x]};last[x]=num; e[++num]=(Edge){x,0,last[y]};last[y]=num; } queue Q; int d[200]; int bfs() { for (int i=1;i<=200;i++) d[i]=-1; while (!Q.empty()) Q.pop(); d[S]=0; Q.push(S); while (!Q.empty()) { int now=Q.front();Q.pop(); for (int j=last[now];j;j=e[j].ne) if (e[j].z&&d[e[j].y]==-1) { d[e[j].y]=d[now]+1; Q.push(e[j].y); if (e[j].y==T) return 1; } } return 0; } int dfs(int i,int low) { if (i==T) return low; int ans=0; for (int j=last[i];j;j=e[j].ne) if (e[j].z&&d[e[j].y]==d[i]+1) { int tmp=dfs(e[j].y, min(low, e[j].z)); e[j].z-=tmp; e[j^1].z+=tmp; ans+=tmp; low-=tmp; if (low==0) break; } return ans; } int check(int mid) { for (int i=0;i<=200;i++) last[i]=c[i]=0; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) { int tp=0; for (int l=0;l