Telecommunication telecowmunication of p1345 cows

Source: Internet
Author: User

Transmission Door

Topic

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.

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.

Analysis

This question is a minimum cut problem, but the ordinary minimum cut is cut edge and this problem is to point, so we consider a point to be split into 2.1 sides, and then a simple solution to the minimum cut can be. Note For the sake of convenience we save the side from 0.

Code

#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cctype>#include<cmath>#include<cstdlib>#include<queue>#include<ctime>#include<vector>#include<Set>#include<map>#include<stack>using namespacestd;Const intinf=1e9+7;ints,t,level[110000],cur[110000],cnt=-1;inthead[110000],to[210000],nxt[210000],w[210000];inlinevoidAddintXintYintv) {to[++cnt]=y; NXT[CNT]=Head[x]; HEAD[X]=CNT; W[CNT]=v; to[++cnt]=x; NXT[CNT]=Head[y]; Head[y]=CNT; W[CNT]=0;} InlineBOOLBFs () {memset (level,-1,sizeof(level)); Queue<int>Q; Level[s]=0;      Q.push (s);  while(!Q.empty ()) {          intx=Q.front ();          Q.pop ();  for(intI=head[x];i;i=Nxt[i]) {              inty=To[i]; if(level[y]==-1&&W[i]) {Level[y]=level[x]+1; if(y==t)return 1;              Q.push (y); }          }      }      return 0;} InlineintDfsintXintYintf) {      if(x==y)returnF; intres=0; if(!cur[x]) cur[x]=Head[x];  for(intI=cur[x];i;i=Nxt[i]) {Cur[x]=i; intj=To[i]; if(level[j]==level[x]+1&&W[i]) {              intNf=dfs (J,y,min (fres,w[i])); Res+=NF; W[i]-=NF; W[i^1]+=NF; }      }      if(!res) level[x]=-1; returnRes;}intMain () {intn,m,i,j,k,x,y,ans=0; memset (Head,-1,sizeof(head)); scanf ("%d%d%d%d",&n,&m,&s,&t);  for(i=1; i<=n;i++) Add (i,i+n,1);  for(i=1; i<=m;i++) {scanf ("%d%d",&x,&y); Add (x+N,y,inf); Add (Y+N,x,inf); } s+=N;  while(BFS ()) {memset (cur,0,sizeof(cur));  while(intA=DFS (S,t,inf)) ans+=A; } printf ("%d\n", ans); return 0;}

Telecommunication telecowmunication of p1345 cows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.