#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int MAXN=1e+3; const int MAXM=1e+5; const int INF = numeric_limits::max(); const LL LL_INF= numeric_limits::max(); struct Edge { int from,to; LL ci;int next; Edge(){} Edge(int _from,int _to,LL _ci,int _next):from(_from),to(_to),ci(_ci),next(_next){} }e[MAXM],e1[MAXM]; int head[MAXN],tot; int dis[MAXN]; int top,sta[MAXN],cur[MAXN],tmp[MAXN]; int vis1[100],vis2[MAXM]; int n; inline void init(){ memset(head,-1,sizeof(head)); tot=0; } inline void AddEdge(int u,int v,LL ci0,LL ci1=0){ e[tot]=Edge(u,v,ci0,head[u]); head[u]=tot++; e[tot]=Edge(v,u,ci1,head[v]); head[v]=tot++; } inline bool bfs(int st,int et){ memset(dis,0,sizeof(dis)); dis[st]=1; queue q; q.push(st); while(!q.empty()){ int now=q.front(); q.pop(); for(int i=head[now];i!=-1;i=e[i].next){ int next=e[i].to; if(vis2[i])continue; if(e[i].ci&&!dis[next]){ dis[next]=dis[now]+1; if(next==et)return true; q.push(next); } } } return false; } LL Dinic(int st,int et){ LL ans=0; while(bfs(st,et)){ top=0; memcpy(cur,head,sizeof(head)); int u=st,i; while(1){ if(u==et){ int pos; LL minn=LL_INF; for(i=0;ie[sta[i]].ci){ minn=e[sta[i]].ci; pos=i; } } for(i=0;i>1; for(int i=1;i<=n;i++){ AddEdge(st,i,mid); AddEdge(i+n,et,mid); } if(Dinic(st,et)==(LL)n*mid){ ans=mid; //if(ans