For each point, split it into two points that have a value of 1, and the original edge is the INF.
The beginning of the edge unity plus N,SS also add n
This is the smallest cut.
#include <iostream>#include <cstring>#include <cstdio>#include <queue>using namespaceStdintN, M, SS, TT, hea[205], CNT, UU, VV, maxflow=0, lev[205];Const intoo=0x3f3f3f3f;queue<int> D;structedge{intToo, NXT, Val;} edge[4005];voidAdd_edge (intFrointToointval) {edge[cnt].nxt = Hea[fro]; Edge[cnt].too = too; Edge[cnt].val = val; Hea[fro] = cnt++;}voidAddedge (intFrointToointval) {Add_edge (fro, too, Val); Add_edge (too, fro,0);}BOOLBFS () {memset (Lev,0,sizeof(Lev)); D.push (ss); LEV[SS] =1; while(!d.empty ()) {intX=d.front (); D.pop (); for(intI=HEA[X]; i!=-1; I=EDGE[I].NXT) {intT=edge[i].too;if(!lev[t] && edge[i].val>0) {Lev[t] = Lev[x] +1; D.push (t); } } }returnlev[tt]!=0;}intDfsintXintLim) {if(X==TT)returnLimintaddflow=0; for(intI=HEA[X]; i!=-1&& addflow<lim; I=EDGE[I].NXT) {intT=edge[i].too;if(Lev[t]==lev[x]+1&& edge[i].val>0){intTmp=dfs (t, Min (Lim-addflow, edge[i].val)); Edge[i].val = tmp; edge[i^1].val + = tmp; Addflow + = tmp; } }returnAddflow;}voidDinic () { while(BFS ()) Maxflow + = DFS (ss, oo);}intMain () {memset (Hea,-1,sizeof(Hea)); cin>>n>>m>>ss>>tt; SS + = N; for(intI=1; i<=n; i++) Addedge (i, I+n,1); for(intI=1; i<=m; i++) {scanf ("%d %d", &uu, &VV); Addedge (uu+n, VV, oo); Addedge (Vv+n, UU, oo); } dinic (); cout<<maxflow<<endl;return 0;}
luogu1345 [USACO5.4] cow's telecom telecowmunication