标签:city ase 条件 ios cstring each strong contain mis
Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 13849 Accepted Submission(s): 6609
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; #define N 20 #define INF 100000000 int cap[N][N]; int flow[N][N]; queue<int>q; int main() { int t,cnt=0; scanf("%d",&t); while(t--) { while(!q.empty()) q.pop(); int n,m; scanf("%d%d",&n,&m); memset(cap,0,sizeof(cap)); for(int i=0; i<m; i++) { int x,y,c; scanf("%d%d%d",&x,&y,&c); if(cap[x][y]!=0) cap[x][y]+=c; else cap[x][y]=c; } int totf=0,a[N],p[N]; memset(flow,0,sizeof(flow)); for(;;) { memset(a,0,sizeof(a)); a[1]=INF; q.push(1); while(!q.empty()) { int u=q.front(); q.pop(); for(int v=1; v<=n; v++) if(!a[v]&&cap[u][v]>flow[u][v]) { p[v]=u; q.push(v); if(cap[u][v]-flow[u][v]>a[u]) a[v]=a[u]; else a[v]=cap[u][v]-flow[u][v]; } } if(a[n]==0) break; for(int u=n; u!=1; u=p[u]) { flow[p[u]][u]+=a[n]; flow[u][p[u]]-=a[n]; } totf+=a[n]; } printf("Case %d: %d\n",++cnt,totf); } return 0; }
标签:city ase 条件 ios cstring each strong contain mis
原文地址:http://www.cnblogs.com/jasonlixuetao/p/6056800.html