Very naked template problem, is to knock up a little trouble.
#include <bits/stdc++.h>using namespacestd;structedge{intV,cap;};Const intMAXN =101; Vector<Edge>E;vector<int>G[MAXN];#definePB push_backvoidAddedge (intUintVintc) {G[u]. PB (E.size ()); E.PB ({v,c}); G[V]. PB (E.size ()); E.PB ({u,0});}ints,t;BOOLVIS[MAXN];intD[MAXN];BOOLBFs () {memset (Vis,0,sizeof(VIS)); Queue<int> q; Q.push (S); D[s] =0; Vis[s] =true; while(Q.size ()) {intU =Q.front (); Q.pop (); for(inti =0; I < g[u].size (); i++) {Edge&e =E[g[u][i]]; if(!VIS[E.V] && e.cap>0) {VIS[E.V]=true; D[E.V]= d[u]+1; Q.push (E.V); } } } returnvis[t];}intCUR[MAXN];intDfsintUinta) { if(U = = t| |! AreturnA; intFlow =0, F; for(int&i = Cur[u]; I < g[u].size (); i++) {Edge&e =E[g[u][i]]; if(D[E.V] = = d[u]+1&& (f = DFS (E.v,min (e.cap,a))) >0) {Flow+=F; E.cap-=F; E[g[u][i]^1].cap + =F; A-=F; if(!a) Break; } } returnflow;}Const intINF =0x3f3f3f3f;intMaxflow () {intFlow =0; while(BFS ()) {memset (cur,0,sizeof(cur)); Flow+=DFS (S,inf); } returnflow;}intCAP[MAXN][MAXN];intMain () {//freopen ("In.txt", "R", stdin); intN,kas =0; while(SCANF ("%d",&N), N) { for(inti =1; I <= N; i++) g[i].clear (); E.clear (); memset (Cap,0,sizeof(CAP)); intM scanf"%d%d%d",&s,&t,&m); while(m--){ intU,v,c; scanf"%d%d%d",&u,&v,&c); CAP[U][V]+=C; Cap[v][u]=Cap[u][v]; } for(inti =1; I <= N; i++) for(intj = i+1; J <= N; J + +)if(cap[i][j]>0) {Addedge (i,j,cap[i][j]); Addedge (J,i,cap[i][j]); } printf ("Network%d\nthe Bandwidth is%d.\n\n",++Kas,maxflow ()); } return 0;}
UVA820 Internet Bandwidth