Description of the "Luogu1345" cow's telecommunication (network flow) problem surface
Farmer John's cows like to keep in touch by email, so they set up a network of dairy computers to communicate with each other. These machines send e-mails as follows: If there is a sequence of C computers a1,a2,..., A (c), and A1 is connected to A2, A2 and A3, and so on, then computer A1 and A (c) can e-mail each other.
Unfortunately, sometimes cows accidentally step on the computer, the farmer John's car may also run over the computer, this bad computer will break down. This means that the computer can no longer be emailed, so the connection to this computer is not available.
Two cows think: if we can't email each other, at least how many computers do we need to break down? Please write a program for them to calculate this minimum value.
Take the following network as an example:
1*
/3-2*
This picture is 3 computers with 2 connections. We want to send information between Computers 1 and 2. Computers 1 and 3, 2 and 3 are directly connected. If the computer 3 is broken, the computer 1 and 2 will not be able to send each other information.
Input/output format
Input format:
The first line consists of four integers separated by spaces: n,m,c1,c2. n is the total number of computers (1<=N<=100) and the computer is numbered 1 to N. M is the total number of connections between computers (1<=m<=600). The last two integers C1 and C2 are the computer numbers used by both cows. The connection is not duplicated and is bidirectional (that is, if C1 is connected to C2, then C2 is connected to C1). There is at most one connection between the two computers. Computer C1 and C2 are not directly connected.
2nd to m+1 the next M-line, each row contains the number of two computers connected directly.
Output format:
An integer representing the minimum number of computers that make computers C1 and C2 Unable to communicate with each other and need to be broken down.
Exercises
The construction of network flow is always a routine
and the network flow of the routine is always built side
To build some,\ (S, t\) to assign a value
It's a little loose ...
This topic is obviously, the requirement is the minimum cut ....
But it is the smallest cut of the point ...
This is a crazy ...
What do we do?
Of course, it's like LCT's plus a point.
and connect all the edges to this point,
And then connect to this point from the current point,
If this point is to be cut off, then this side will not go.
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <set>#include <map>#include <queue>#include <vector>using namespaceStd#define MAXL 50000#define MAX#define INF 1e8inline intRead () {intx=0, t=1;CharCh=getchar (); while((ch<' 0 '|| Ch>' 9 ') &&ch!='-') Ch=getchar ();if(ch=='-') t=-1, Ch=getchar (); while(ch<=' 9 '&&ch>=' 0 ') x=x*Ten+ch-48, Ch=getchar ();returnX*t;}structline{intV,next,w;} E[MAXL];inth[max],cnt;intN,m,s,t;inline voidADD (intUintVintW) {e[cnt]= (line) {v,h[u],w}; h[u]=cnt++;}intLevel[max];intCur[max];BOOLBFS () {memset (level,0,sizeof(level)); level[s]=1; queue<int> Q; Q.push (S); while(! Q.empty ()) {intU=q.front (); Q.pop (); for(inti=h[u];i!=-1; i=e[i].next) {intV=E[I].V;if(E[i].w&&!level[v]) Level[v]=level[u]+1, Q.push (v); } }returnLEVEL[T];}intDFS (intUintFlow) {if(flow==0|| U==T)returnFlowintret=0; for(int&i=cur[u];i!=-1; i=e[i].next) {intV=E[I].V;if(E[i].w&&level[v]==level[u]+1) {intDd=dfs (V,min (FLOW,E[I].W)); FLOW-=DD;RET+=DD; e[i].w-=dd;e[i^1].W+=DD; } }returnRET;}intDinic () {intret=0; while(BFS ()) { for(intI=1; i<=n+n;++i) Cur[i]=h[i]; Ret+=dfs (S,inf); }returnRET;}intMain () {memset (H,-1,sizeof(h)); N=read (); M=read (); S=read () +n; T=read (); for(intI=1; i<=m;++i) {intU=read (), V=read (); ADD (U+n,v,inf); ADD (V,u+n,0); ADD (V+n,u,inf); ADD (U,v+n,0); } for(intI=1; i<=n;++i) Add (I,i+n,1), Add (I+n,i,0); Cout<<dinic () <<endl;return 0;}
Telecommunications of "Luogu1345" cows (network flow)