The point connecting component of the undirected graph is obtained, and a point is split into an in point and an out point, and a forward edge with a capacity of 1 is used to indicate that it is usable once. Maximum flow for minimum cut can be.
Something of some detail: 1. The source point is fixed, and the meeting point is to be enumerated again, since the minimum cut will form a connecting component, and the cut will be larger in the connected component of the source point.
2. Build one for each weight lifting. 3. The point in and out from the point of entry is considered to have passed the original point, then the source and meeting point is not necessary to pass, so one in the out point, another enumeration in the point.
#include <bits/stdc++.h>using namespacestd;Const intMAXN =102;structedge{intv,cap,nxt;}; Vector<Edge>E;vector<Edge>Bak;#definePB push_backintHEAD[MAXN];voidAddedge (intUintVintc) {bak. PB ({V,c,head[u]}); Head[u]= Bak.size ()-1; Bak. PB ({u,0, Head[v]}); HEAD[V]= Bak.size ()-1;}intS,T,CUR[MAXN],D[MAXN],Q[MAXN];BOOLBFs () {memset (d,0,sizeof(d)); intL =0, r =0; Q[r+ +] = S; D[s] =1; while(r>l) { intU = q[l++]; for(inti = Head[u]; ~i; i =e[i].nxt) {Edge&e =E[i]; if(!D[E.V] && e.cap>0) {D[E.V]= D[u] +1; Q[r++] =e.v; } } } returnd[t];}intDfsintUinta) { if(U = = t| |! AreturnA; intFlow =0, F; for(int&i = Cur[u]; ~i; i =e[i].nxt) {Edge&e =E[i]; if(D[E.V] = = d[u]+1&& (f = DFS (E.v,min (A,E.CAP))) >0) {Flow+ = f; A-=F; E.cap-= f; e[i^1].cap + =F; if(!a) Break; } } returnflow;}Const intINF =0x3f3f3f3f;intMaxflow () {intFlow =0; while(BFS ()) {memcpy (Cur,head,sizeof(head)); Flow+=DFS (S,inf); } returnflow;}intn,m;voidinit () {memset (head,-1,sizeof(head)); Bak.clear ();}intMain () {//freopen ("In.txt", "R", stdin); while(~SCANF ("%d%d",&n,&m)) {init (); for(inti =1; I < n; i++) Addedge (I,i+n,1); for(inti =0; I < m; i++){ intU,v; scanf"(%d,%d)",&u,&v); Addedge (U+n,v,inf); Addedge (v+N,u,inf); } intAns =N; S=N; for(T =1; T < n; t++) {E=Bak; Ans=min (Ans,maxflow ()); } printf ("%d\n", ans); } return 0;}
UVA1660 Cable TV Network