Cable TV Network
Time Limit: 1000MS |
|
Memory Limit: 30000K |
Total Submissions: 4690 |
|
Accepted: 2170 |
Description
The interconnection of the relays in a cable TV network is bi-directional. The network is connected if there are at least one interconnection path between each pair of relays present in the network. Otherwise the network is disconnected. An empty network or a network with a single relay is considered connected. The safety factor F of a network with n relays is:
1. N, if the net remains connected regardless the number of relays removed from the net.
2. The minimal number of relays that disconnect the network when removed.
For example, consider the Nets from Figure 1, where the circles mark the relays and the solid lines correspond to Intercon Nection cables. The network (a) is connected regardless the number of relays that was removed and, according to rule (1), f=n=3. The network (b) is disconnected when 0 relays was removed, hence f=0 by rule (2). The network (c) is disconnected while the relays 1 and 2 or 1 and 3 are removed. The safety factor is 2.
Input
Write A program This reads several data sets from the standard input and computes the safety factor for the cable networks Encoded by the data sets. Each data set starts with a integers:0<=n<=50,the number of relays in the net, and M, the number of cables in the Net. Follow m data pairs (u,v), u < V, where u and V is relay identifiers (integers in the range 0..n-1). The pair (U,V) designates the cable that interconnects the relays U and v. The pairs may occur on any order. Except the (u,v) pairs, which do not contain white spaces, white spaces can occur freely in input. Input data terminate with an end of file and is correct.
Output
For each data set, the program prints on the standard output, from the beginning of a line, the safety factor of the Encod Ed Net.
Sample Input
0 01 03 3 (0,1) (0,2) 2 05 7 (0,1) (0,2) (1,3) (1,4) (2,3) (3,4)
Sample Output
01302
Hint
The first data set encodes a empty network, the second data set corresponds to a network with a single relay, and the FOL lowing three data sets encode the nets shown in Figure 1.
Source
Southeastern Europe 2004 Test Instructions:
An undirected graph is given to find the point connectivity
Point of Connectivity:
At least how many points can be removed to make the non-direction diagram is not connected, it seems that the problem is stipulated if ans=n-1 output n ...
Analysis:
Point-to-edge transformation of a network stream: to split a point into two points, with one edge in the middle, and a record point of information
We enumerate a sink point of a source point, and then for each non-sink point from the in point to the out point a capacity of 1 edge, the source point of the meeting point between the point of Access is INF, and then for the edge of the original image (U,v), we from the point of Origin of the U to V point to a side of the INF, You can then build a super-source point, a super-sink point, a super-source point to the source point's in-point edge, the point of the meeting point to the super-sink point edge ...
Code:
1#include <algorithm>2#include <iostream>3#include <cstring>4#include <cstdio>5 //by Neighthorn6 #defineINF 0x3f3f3f3f7 using namespacestd;8 //Dapeng Day with the wind, soaring 90,000 miles9 Ten Const intmaxn= $+5, maxm=maxn*maxn*2+5; One A intN,M,S,T,CNT,HD[MAXN],TO[MAXM],FL[MAXM],MP[MAXN][MAXN],NXT[MAXM],POS[MAXN]; - -InlinevoidAddintSintXinty) { thefl[cnt]=s;to[cnt]=y;nxt[cnt]=hd[x];hd[x]=cnt++; -fl[cnt]=0; to[cnt]=x;nxt[cnt]=hd[y];hd[y]=cnt++; - } - +InlineBOOLBFsvoid){ -memset (pos,-1,sizeof(POS)); + intHead=0, tail=0, Q[MAXN]; Aq[0]=s,pos[s]=0; at while(head<=tail) { - inttop=q[head++]; - for(inti=hd[top];i!=-1; i=Nxt[i]) - if(pos[to[i]]==-1&&Fl[i]) -pos[to[i]]=pos[top]+1, q[++tail]=To[i]; - } in returnpos[t]!=-1; - } to +InlineintFindintVintf) { - if(v==T) the returnF; * intres=0, T; $ for(inti=hd[v];i!=-1&&f>res;i=Nxt[i])Panax Notoginseng if(pos[to[i]]==pos[v]+1&&Fl[i]) -T=find (To[i],min (fl[i],f-res)), fl[i]-=t,fl[i^1]+=t,res+=T; the if(!Res) +pos[v]=-1; A returnRes; the } + -InlineintDinic (void){ $ intres=0, T; $ while(BFS ()) - while(t=find (S,inf)) -res+=T; the returnRes; - }Wuyi theSigned Main (void){ - while(SCANF ("%d%d", &n,&m)! =EOF) { WuMemset (MP,0,sizeof(MP)); - intAns=inf; s=0, t=n*2+1; About for(intI=1, x,y;i<=m;i++) $scanf"(%d,%d)", &x,&y), x++,y++,mp[x][y]=1; - for(intI=1; i<=n;i++) - for(intj=1; j<=n;j++) - if(i!=j) { Amemset (hd,-1,sizeof(HD)); Cnt=0; + for(intx=1; x<=n;x++) the if(x!=i&&x!=j) -Add1, x,x+n); $ for(intx=1; x<=n;x++) the for(inty=1; y<=n;y++) the if(Mp[x][y]) theAdd (Inf,x+n,y), add (inf,y+n,x); theAdd (Inf,i,i+n), add (Inf,j,j+n), add (Inf,s,i), add (inf,j+n,t); ans=min (Ans,dinic ()); - } in if(ans>=inf) theans=N; theprintf"%d\n", ans); About } the return 0; the}//The cap ou pas Cap. Cap.
View Code
by Neighthorn
POJ 1966 Cable TV Network