http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11545
Just ask not to go through the same side, then each time to find an augmented road T--, Judge T<=0 can.
When adding edges, pay attention to c<=c when you need to add edge.
adjacency table:
1# include <cstdio>2# include <cstring>3# include <algorithm>4# include <iostream>5 using namespacestd;6 7 intlist[1020],dis[1020],gap[1020],node;8 intSource,sink,vs,inf =1<< -;9 intn,m,t,c;Ten structE One { A intTo,c,next; -}edg[100002]; - the voidADDEDG (int from,intTo,intvalue) - { -edg[node].to = to,edg[node].c = Value,edg[node].next = list[ from],list[ from] = node++; -Edg[node].to = from, edg[node].c =0, Edg[node].next = list[to],list[to] = node + +; + } - + intDfsintSrcint( ) A { at if(src = = sink)return; - - intFlow =0, Mid_d = vs-1; - for(intj = list[src];j! =-1; j =edg[j].next) - if(EDG[J].C) - { in if(DIS[SRC] = = dis[edg[j].to]+1) - { to intt = DFS (Edg[j].to,min (aug-flow,edg[j].c)); + -EDG[J].C-=T; theedg[j^1].C + =T; *Flow + =T; $ if(Dis[source] >= Vs)returnflow;Panax Notoginseng if(* = flow) Break; - } theMid_d =min (mid_d,dis[edg[j].to]); + } A if(!flow) the { + if(! (--GAP[DIS[SRC])) Dis[source] =Vs; -DIS[SRC] = mid_d+1; $++GAP[DIS[SRC]]; $ } - returnflow; - } the - BOOLMAXFLOW_SAP (intSrcinted)Wuyi { the intAns =0; -Memset (Gap,0,sizeof(GAP)); Wumemset (DIS,0,sizeof(DIS)); -gap[0] = Vs =Ed; AboutSource = src, sink =Ed; $ - while(Dis[source] <Vs) - { - //printf ("%d%d\n", T,ans); A if(Dfs (source,inf)) +t--; the if(t<=0) Break; - } $ if(t<=0)return true; the return false; the the } the - intMain () in { the //freopen ("A.txt", "R", stdin); the while(~SCANF ("%d%d%d%d",&n,&m,&t,&C)) About { the inti,j; thenode =0; thememset (list,-1,sizeof(list)); + for(i =0; I < m;i++) - { the intx,y,c;Bayiscanf"%d%d%d",&x,&y,&c); the //printf ("%d%d%d\n", x,y,c); the if(c<=C) addedg (x,y,c); - } - if(Maxflow_sap (1, N)) printf ("yes\n"); the Elseprintf"no\n"); the } the return 0; the}
hunnu-11545 Xiao Ming's Troubles--Finding the path (maximum flow)