标签:飞机 continue span 二分图 php 网络流24题 logs using image
★★☆ 输入文件:flyer.in
输出文件:flyer.out
简单对比
时间限制:1 s 内存限制:128 MB
1 #include <algorithm> 2 #include <cstring> 3 #include <cstdio> 4 5 using namespace std; 6 7 const int INF(0x7fffffff); 8 const int N(233); 9 int n,n1,u,v,w; 10 11 int head[N],sumedge; 12 struct Edge 13 { 14 int to,next,val; 15 Edge(int to=0,int next=0,int val=0): 16 to(to),next(next),val(val){} 17 }edge[N<<1]; 18 inline void ins(int u,int v,int w) 19 { 20 edge[++sumedge]=Edge(v,head[u],w); 21 head[u]=sumedge; 22 } 23 struct Type_AC 24 { 25 int s,t,ret; 26 int deep[N]; 27 bool BFS() 28 { 29 memset(deep,-1,sizeof(deep)); 30 int tail=0,hd=0,que[N]; 31 deep[s]=0; que[tail++]=s; 32 for(;hd<tail;) 33 { 34 int fro=que[hd++]; 35 for(int i=head[fro];i;i=edge[i].next) 36 { 37 int v=edge[i].to; 38 if(deep[v]==-1&&edge[i].val) 39 { 40 deep[v]=deep[fro]+1; 41 que[tail++]=v; 42 } 43 } 44 } 45 if(deep[t]!=-1) return true; 46 return false; 47 } 48 int DFS(int now,int flow) 49 { 50 if(now==t||!flow) return flow; 51 int go,flux=0; 52 for(int i=head[now];i;i=edge[i].next) 53 { 54 int v=edge[i].to; 55 if(deep[v]!=deep[now]+1||edge[i].val<=0) continue; 56 go=DFS(v,min(edge[i].val,flow-flux)); 57 edge[i].val-=go; 58 edge[i^1].val+=go; 59 flux+=go; 60 if(flux==flow) return flow; 61 } 62 if(!flux) deep[now]=-1; 63 return flux; 64 } 65 void Dinic() 66 { 67 for(;BFS();) ret+=DFS(s,INF); 68 } 69 }I_want_AC; 70 71 int main() 72 { 73 freopen("flyer.in","r",stdin); 74 freopen("flyer.out","w",stdout); 75 76 scanf("%d%d",&n,&n1); 77 for(int i=1;i<=n1;i++) ins(0,i,1),ins(i,0,0); 78 for(int i=n1+1;i<=n;i++) ins(i,n+1,1),ins(n+1,i,0); 79 for(;~scanf("%d%d",&u,&v);) ins(u,v,1); ins(v,u,0); 80 I_want_AC.s=0; 81 I_want_AC.t=n+1; 82 I_want_AC.Dinic(); 83 printf("%d\n",I_want_AC.ret); 84 return 0; 85 }
标签:飞机 continue span 二分图 php 网络流24题 logs using image
原文地址:http://www.cnblogs.com/Shy-key/p/7251784.html