Looking for a long time the difference between the two ... UVA820 wa a lot of times. However, after the template, you can find the maximum flow between any two points.
UVA is a graph, so there may be heavy edges, POJ 1273 is a graph, and is the single source point for the maximum flow, so when changing the template to pay attention to.
And I actually made a more stupid mistake, in order to re-edge the need to choose the largest, positive solution should be cumulative ....
1#include <stdio.h>2#include <queue>3#include <string.h>4 #defineINF 9999995 using namespacestd;6 ints,t,n,m;7 intmap[407][407],flow[407][407];8 intp[407],a[407];9 intEK (intSintt)Ten { Onequeue<int>Q; A intsum=0; -memset (Flow,0,sizeof(flow)); - while(1) the { -Memset (A,0,sizeof(a)); -a[s]=INF; - Q.push (s); + while(!q.empty ()) - { + intu=Q.front (); A Q.pop (); at for(intI=1; i<=m; i++) - { - if(!a[i]&&flow[u][i]<Map[u][i]) - { -p[i]=u; - Q.push (i); ina[i]=a[u]<map[u][i]-flow[u][i]?a[u]:map[u][i]-Flow[u][i]; - } to } + } - if(!a[t]) Break; the for(inti=t; I!=s; I=P[i]) * { $flow[p[i]][i]+=A[t];Panax Notoginsengflow[i][p[i]]-=A[t]; - } thesum+=A[t]; + } A returnsum; the } + intMain () - { $ intcas=1; $ while(SCANF ("%d",&m), m) - { -scanf"%d%d%d",&s,&t,&n); thememset (Map,0,sizeof(map)); - inta,b,c;Wuyi for(intI=0; i<n; i++) the { -scanf"%d%d%d",&a,&b,&c); Wumap[a][b]+=C; -map[b][a]=Map[a][b]; About } $ intmaxx=EK (s,t); -printf"Network%d\n", cas++); -printf"The bandwidth is%d.\n\n", Maxx); - } A return 0; +}UVA 820 Direct ek template on
Can be compared with the POJ 1273 map
commented out a plus edge
POJ 1273 Examples to
2 2
1 2 3
1 2 5 The answer is 8.
2 2
1 2 3
2 1 5 The answer is 3.
UVA 820---POJ 1273 Max stream