poj1966 Cable TV Network

Cable TV Network
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 4956   Accepted: 2292

Description

The interconnection of the relays in a cable TV network is bi-directional. The network is connected if there is 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 interconnection cables. The network (a) is connected regardless the number of relays that are removed and, according to rule (1), f=n=3. The network (b) is disconnected when 0 relays are removed, hence f=0 by rule (2). The network (c) is disconnected when the relays 1 and 2 or 1 and 3 are removed. The safety factor is 2.

Input

Write a program that 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 two 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 are 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 in 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 are correct.

Output

For each data set, the program prints on the standard output, from the beginning of a line, the safety factor of the encoded net.

Sample Input

0 0
1 0
3 3 (0,1) (0,2) (1,2)
2 0
5 7 (0,1) (0,2) (1,3) (1,2) (1,4) (2,3) (3,4)

Sample Output

0
1
3
0
2

Hint

The first data set encodes an empty network, the second data set corresponds to a network with a single relay, and the following three data sets encode the nets shown in figure 1.


题解:

       大致的题意就是给定一个无向图,求最少去掉多少个点,可以使剩下的图不联通。如果无论删多少个点,剩下的图仍联通,则输出点数N。点数<=50。

       若无向图不连通,则图中必有两个点不连通。可以枚举这两个点S和T,求在剩下的N-2的点中最少去掉多少个点能使图不连通。在每次枚举的过程中取最小值即为答案。

       “去掉最少的的点使S,T不连通”,容易想到网络流的最大流最小割。但不同的是最小割球的是“边”,而这道题求的是“点”。所以做这道题有一个重要的技巧:拆点

       拆点,顾名思义就是把点拆开,所以我们可以按照下面的方法构建一个网络:

       1.把原来无向图的点差成x和x+n两个点。

       2.对每一个点连接一条有向边(x,x+n),容量为1.

       3.对于原无向图中的每一条边(x,y),在网络中连有向边(x+n,y),(y,x+n),容量为正无穷。

       以S为源点,T为汇点,求最小割即最大流,答案即为最少需要去掉的点数。

       将点拆成两个点,并连接一条有向边,容量为1,这样要想经过这个点就相当于必须流经这条边。所以删去一个点,就等价于断开这条边。


代码(16ms):

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

const int inf=1e9+7;
const int Max=1e3+7;
int size,ans,n,m,minn,s,t;
int depth[Max],first[Max],map[55][55];
struct shu{int to,len,next;};
shu bian1[Max],bian[Max];

inline int get_int()
{
   int x=0,f=1;
   char c;
   for(c=getchar();(!isdigit(c))&&(c!='-');c=getchar());
   if(c=='-') {f=-1;c=getchar();}
   for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+c-'0';
   return x*f;
}

inline void clean()
{
   size=1;
   memset(first,0,sizeof(first));
   memset(bian1,0,sizeof(bian1));
   memset(bian,0,sizeof(bian));
   memset(map,0,sizeof(map));
}

inline void build(int x,int y,int z)
{
   size++;
   bian1[size].next=first[x];
   first[x]=size;
   bian1[size].to=y;
   bian1[size].len=z;
}

inline bool bfs()
{
   memset(depth,0,sizeof(depth));
   queueq;
   q.push(s);
   depth[s]=1;
   while(!q.empty())
   {
   	 int point=q.front();
   	 q.pop();
   	 for(int u=first[point];u;u=bian[u].next)
   	 {
   	   if(!depth[bian[u].to]&&bian[u].len)
   	   {
   	   	 depth[bian[u].to]=depth[point]+1;
   	   	 q.push(bian[u].to);
   	   }
   	 }
   }
   return depth[t];
}

inline int dinic(int point,int flow)
{
   int sum=0;
   if(point==t) return flow;
   for(int u=first[point];u&&sum

你可能感兴趣的:(网络流-最大流*,poj)