标签:des style blog color io os ar java for
Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 8394 Accepted Submission(s): 3910
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include <queue> 6 #include <vector> 7 using namespace std; 8 9 #define N 20 10 #define inf 999999999 11 12 vector<int>ve[N]; 13 int map[N][N], flow[N], father[N]; 14 int n, m; 15 16 int bfs(){ 17 int i, j, k, u, v, st=1, end=n; 18 queue<int>Q; 19 while(!Q.empty()) Q.pop(); 20 Q.push(st); 21 memset(father,-1,sizeof(father)); 22 father[st]=st;flow[st]=inf; 23 while(!Q.empty()){ 24 u=Q.front();Q.pop(); 25 for(i=0;i<ve[u].size();i++){ 26 v=ve[u][i]; 27 if(v!=st&&father[v]==-1&&map[u][v]!=0){ 28 flow[v]=min(flow[u],map[u][v]); 29 father[v]=u; 30 Q.push(v); 31 } 32 } 33 } 34 if(father[end]==-1) return -1; 35 return flow[end]; 36 } 37 38 int solve(){ 39 int st=1, end=n, max_flow=0; 40 int step; 41 while((step=bfs())!=-1){ 42 max_flow+=step; 43 int u=end; 44 while(u!=st){ 45 map[father[u]][u]-=step; 46 map[u][father[u]]+=step; 47 u=father[u]; 48 } 49 } 50 return max_flow; 51 } 52 main() 53 { 54 int t, i, j, k, kase=1; 55 int x, y, z; 56 cin>>t; 57 while(t--){ 58 scanf("%d %d",&n,&m); 59 for(i=0;i<=n;i++) ve[i].clear(); 60 memset(map,0,sizeof(map)); 61 while(m--){ 62 scanf("%d %d %d",&x,&y,&z); 63 ve[x].push_back(y);ve[y].push_back(x); 64 map[x][y]+=z; 65 } 66 printf("Case %d: %d\n",kase++,solve()); 67 } 68 }
标签:des style blog color io os ar java for
原文地址:http://www.cnblogs.com/qq1012662902/p/4022129.html