Rokua P1345 [USACO5.4] cow's telecom telecowmunication

Source: Internet
Author: User

P1345 [USACO5.4] cow's telecom telecowmunicationTitle Description

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 formatInput 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.

input/Output sampleInput Sample # #: Copy
3 2 1 21 32 3
Output Example # #: Replication
1
Test instructions:
? n the undirected graph of a point m edge, there may be multiple edges between points and points, and the least points are removed, so that the given two points are not connected.
Idea: First split, then the smallest cut, that is, run maximum flow = minimum cut.
#include <queue>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#defineMAXN 10000using namespaceStd;queue<int>que;intSCR,DECC;intn,m,c1,c2;intans=0, tot=1;intCUR[MAXN],LEV[MAXN];intTO[MAXN],NET[MAXN],HEAD[MAXN],CAP[MAXN];voidAddintUintVintW) {to[++tot]=v;net[tot]=head[u];cap[tot]=w;head[u]=tot; to[++tot]=u;net[tot]=head[v];cap[tot]=0; head[v]=tot;}BOOLBFs () { for(intI=1; i<=2*n;i++) {Lev[i]=-1; Cur[i]=Head[i]; }     while(!que.empty ()) Que.pop ();    Que.push (SCR); LEV[SCR]=0;  while(!Que.empty ()) {        intnow=Que.front ();        Que.pop ();  for(intI=head[now];i;i=Net[i])if(lev[to[i]]==-1&&cap[i]>0) {Lev[to[i]]=lev[now]+1;                Que.push (To[i]); if(TO[I]==DECC)return true; }        }    return false;}intDinic (intNowintflow) {    if(NOW==DECC)returnflow; intrest=0, Detal;  for(int& i=cur[now];i;i=Net[i])if(lev[to[i]]==lev[now]+1&&Cap[i]) {Detal=dinic (To[i],min (flow-rest,cap[i])); if(detal) {Cap[i]-=Detal; Cap[i^1]+=Detal; Rest+=Detal; if(Rest==flow) Break; }        }    if(Rest!=flow) lev[now]=-1; returnrest;}intMain () {CIN>>n>>m>>c1>>C2;  for(intI=1; i<=n;i++) Add (I,i+n,1);  for(intI=1; i<=m;i++){        intx, y; CIN>>x>>y; Add (x+n,y,0x7f7f7f7f); Add (Y+n,x,0x7f7f7f7f); } SCR=c1+n;decc=C2;  while(BFS ()) ans+=dinic (SCR,0x7f7f7f7f); cout<<ans;}

Rokua P1345 [USACO5.4] cow's telecom telecowmunication

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.