Cable TV Network
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 4563   Accepted: 2118

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
 
题意:
给出n个点,m条边。求该图的连通度。
f的定义是:
1.f为n,如果不管删除多少个顶点,剩下的图仍然是连通的
2.f为删除最少的顶点数,使得剩下的图不连通
 
思路:
把点i拆成2个点i' i'',i'到i''建边,值为1。
对于原图中相连的边(u,v),从u''连边到v',从v''连边到u',因为是无向图,权值为INF。
固定源点,枚举汇点,跑最大流,取最小值,如果最后的值为INF,说明是完全图,则在该题中
答案为n。否则为最大流的值。
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1<<30
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
struct node{
int to;
int val;
int next;
}edge[MAXN*MAXN],edge2[MAXN*MAXN];
int pre[MAXN],vis[MAXN],ind,n,m,S,T;
void add(int x,int y,int z){
edge2[ind].to = y;
edge2[ind].val = z;
edge2[ind].next = pre[x];
pre[x] = ind ++;
}
bool bfs(int S,int T){
memset(vis,-,sizeof(vis));
queue<int>q;
vis[S] = ;
q.push(S);
while(!q.empty()){
int tp = q.front();
q.pop();
for(int i = pre[tp]; i != -; i = edge[i].next){
int t = edge[i].to;
if(vis[t] == - && edge[i].val){
vis[t] = vis[tp] + ;
q.push(t);
}
}
}
return vis[T] != -;
}
int dfs(int rt,int low){
if(rt == T){
return low;
}
int used = ;
for(int i = pre[rt]; i != - && used < low; i = edge[i].next){
int t = edge[i].to;
if(vis[t] == vis[rt] + && edge[i].val){
int b = dfs(t,min(low-used,edge[i].val));
used += b;
edge[i].val -= b;
edge[i^].val += b;
}
}
if(used == )vis[rt] = -;
return used;
}
int dinic(int S,int T){
int ans = ;
while(bfs(S,T)){
while(){
int a = dfs(S,INF);
if(a == )break;
ans += a;
}
}
return ans;
}
int main(){
while(~scanf("%d%d",&n,&m)){
if(m == ){
if(n == )
printf("1\n");
else
printf("0\n");
continue;
}
ind = ;
memset(pre,-,sizeof(pre));
for(int i = ; i <= m; i++){
int x,y;
scanf(" (%d,%d)",&x,&y);
x ++,y ++;
add(x+n,y,INF),add(y,x+n,);
add(y+n,x,INF),add(x,y+n,);
}
for(int i = ; i <= n; i++){
add(i,i+n,),add(i+n,i,);
}
int ans = INF;
for(int i = ; i <= n; i++){
for(int j = ; j < ind; j++){
edge[j] = edge2[j];
}
S = + n,T = i;
ans = min(ans,dinic(S,T));
}
if(ans == INF)ans = n;
printf("%d\n",ans);
}
return ;
}

poj1966 求顶点连通度的更多相关文章

  1. poj 1966(顶点连通度)

    题意:给出一个n个节点和m条边的图,求该图的顶点连通度. 分析: 顶点连通度的求解可以转换为网络最大流问题. (1)原图G中的每个顶点v变成网络中的两个顶点v‘和v’‘,顶点v’至v''有一个条弧(有 ...

  2. POJ--1966--Cable TV Network【无向图顶点连通度】

    链接:http://poj.org/problem?id=1966 题意:一个无向图,n个点,m条边,求此图的顶点连通度. 思路:顶点连通度,即最小割点集里的割点数目.一般求无向图顶点连通度的方法是转 ...

  3. Cable TV Network 顶点连通度 (最大流算法)

    Cable TV Network 题目抽象:给出含有n个点顶点的无向图,给出m条边.求定点联通度   K 算法:将每个顶点v拆成 v'   v''  ,v'-->v''的容量为1.       ...

  4. Algorithm --> 树中求顶点A和B共同祖先

    树中求顶点A和B共同祖先 题目: 给定一颗树,以及两个顶点A和B,求最近的共同祖先,和包含的子顶点个数? 比如:给定如下图的树,以及顶点13和8,则共同祖先为3,以3为root的子顶点共有8个

  5. POJ 1966 Cable TV Network(顶点连通度的求解)

                               Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissi ...

  6. poj 1966 Cable TV Network 顶点连通度

    题目链接 给一个图, n个点m条边, 求至少去掉多少个点可以使得图不再联通.随便指定一个点为源点, 枚举其他点为汇点的情况, 跑网络流, 求其中最小的情况. 如果最后ans为inf, 说明是一个完全图 ...

  7. osg shader 相机观察矩阵逆矩阵 求顶点世界坐标

    uniform mat4 osg_ViewMatrixInverse;//osg内置uniform void main() { vec4 posWorld = osg_ViewMatrixInvers ...

  8. poj1815Friendship(最小割求割边)

    链接 题意为去掉多少个顶点使图不连通,求顶点连通度问题.拆点,构造图,对于<u,v>可以变成<u2,v1> <v2,u1>容量为无穷,<u1,u2>容量 ...

  9. 求割点模板(可求出割点数目及每个割点分割几个区域)POJ1966(Cable TV Network)

    题目链接:传送门 题目大意:给你一副无向图,求解图的顶点连通度 题目思路:模板(图论算法理论,实现及应用 P396) Menger定理:无向图G的顶点连通度k(G)和顶点间最大独立轨数目之间存在如下关 ...

随机推荐

  1. 快速编写代码zencode

    #是 id .是class $是数字 {}是标签中内容 *个数 ^上一级

  2. 未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序解决办法

    一.未在本地计算机上注册“microsoft.ACE.oledb.4.0”提供程序 http://download.microsoft.com/download/7/0/3/703ffbcb-dc0c ...

  3. [转]Linux后台进程管理利器:supervisor

    FROM : http://www.liaoxuefeng.com/article/0013738926914703df5e93589a14c19807f0e285194fe84000 Linux后台 ...

  4. tcpip的可靠性

             

  5. 洛谷 1016 / codevs 1046 旅行家的预算

    https://www.luogu.org/problem/show?pid=1016 http://codevs.cn/problem/1046/ 题目描述 Description 一个旅行家想驾驶 ...

  6. 全球第一本基于Bootstrap V3.x的图书《深入理解Bootstrap》终于上市了,再次免费送书15本【活动结束】

    先说活动规则,再说书的事 经过将近1年的努力,终于有了第一本自己独立编写的书:<深入理解Bootstrap>,基于最新版V 3.1 ,侧重于源码详解.架构分析.插件扩展(全新开发)实战.为 ...

  7. Android 的图片异步请求加三级缓存 ACE

    使用xUtils等框架是很方便,但今天要用代码实现bitmapUtils 的功能,很简单, 1 AsyncTask请求一张图片 ####AsyncTask #####AsyncTask是线程池+han ...

  8. 重建中国.NET生态系统

    Neuzilla官方微信公众号:搜 架构师联盟 或 neuzilla 我是.NET铁杆粉丝,所以如果你要在评论里跟我撕逼.NET怎么怎么烂,Java.C++.PHP.JavaScript怎么怎么好,我 ...

  9. .net异步编程

    现在电脑大部分都是多核心,在处理多线程方便有很大优势,异步调用方法的时候可以立即返回执行其他程序,进行异步编程会让程序运行效率更高. 我也是刚刚关注异步编程方面知识,也有很多不是很理解,所以想向大神请 ...

  10. Windows Phone 8 显示当前项目的使用内存,最大峰值,最大内存上限

    public static class MemoryDiagnosticsHelper { public static bool isStart = false; static Popup popup ...