It is not understandable that the 0ms on the evaluation station is how to get out.
The problem became gentler and cuter after the creation of the super-source and super-meeting points. In fact, it is gentle and lovely. Compare what you can find:
(1) Aidemont Kap algorithm (2) Dinnick algorithm (3) Improved version Aidemont Kap algorithm (MY method)
Not to tube that 0ms, then (3) algorithm is the most wonderful "its alias is: ISAP", time objective.
This is even a ISAP template bar (in addition to the input of the ugly few lines, the rest are standard rice cake template!) )
1 #include <stdio.h> 2 # Include<algorithm> 3 #include <queue> 4 #include <cstring> 5 #define Go (i,a,b) for (int i=a;i<=b;i++) 6 #define FO (i,a,x) for (int i=a[x],v=e[i].v;i>-1;i=e[i].next,v=e[i].v) 7 #define Mem (A, B) memset (A,b,sizeof (a)) 8 using namespace std; const int N=5000 ; 9 struct e{int v,next,flow,cap;} e[n* N]; 0 int n,n_power,n_user,m,s,t,head[n],k= , d[n]; int num[n],cur[n],pree[n],pren[n]; void ADD (int u,int v,int flow,int cap) {E[k ]= (E) {v,head[u],flow,cap};head[u]=k++;} void BFS () { queue<int>q; BOOL vis[n]={0};q.push (T);d [t]=0 ; - while (! q.empty ()) - {u=int Q.front (); Q.pop (); Fo (i,head,u)if(!e[i].cap&&! Vis[v]) vis[v]=1, d[v]=d[u]+1 , Q.push (v); + } } u,a= int ()} () {int '2147483645 ; u=t; while (u!=s) {int i=pree[u];a=min (a,e[i].cap-e[i].flow); u= pren[u];} u=t; while (u!=s) {int i=pree[u];e[i].flow+=a;e[i^1].flow-=a;u=pren[u];} return A;} the int main () {while (~scanf ("%d%d%d%d", &n, &n_power,&n_user,& m)) - { s=0; t=n+1; Char _;mem (head,-1 ); Go (i,1, m) {int u,v,cap;scanf (" %c%d%c%d%c%d", &_,&u,&_,&v,&_,& cap); u++,v++; ADD (U,v,0, CAP); ADD (V,u,0,0 );} to go (i,1, n_power) {int v,cap;scanf (" %c%d%c%d", &_,&v,&_,& cap); v++; ADD (S,v,0, CAP); ADD (V,s,0,0 );} Go (i,1, n_user) {int u,cap;scanf (" %c%d%c%d", &_,&u ,&_,& cap); u++; ADD (U,t,0, CAP); ADD (T,u,0,0);} BFS (); Mem (num,0 ); * n+ Go (i,0,1) num[d[i]]++,cur[i]= Head[i]; Panax Notoginseng int u=s,flow=0 ; - while (d[s]<t+1 ) { U==t?flow+=aug (), U=s:1; BOOL retreat=1 ; (i,cur,u) if(e[i].cap>e[i].flow&&d[u]==d[v]+1 ) (retreat=0; cur[u]=pree[v]=i;pren[v]=u;u=v; Break;} if(!retreat)continue ; $ $ int Min=t;fo (i,head,u) {if(e[i].cap>e[i].flow) min= min (min,d[v]);} - if (! (--num[d[u])) break; num[d[u]=min+1]++ ; cur[u]=head[u];u==s? 1: u= Pren[u]; the } printf ("%d\n" , flow); { 0}return ;} // Paul_guderian
"Improved version Aidemont KAP algorithm"
Network Flow Two learning points: learn to transform the problem, learn a few models? Are you questioning the authority of the magic rice pie? Then I'll give you a rice cake!
Zbh not to play with Isaac's union ... I wrote this blog to express my anger!
"POJ 1459 Power Network"