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

  1. 0 0
  2. 1 0
  3. 3 3 (0,1) (0,2) (1,2)
  4. 2 0
  5. 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。否则为最大流的值。
  1. #include<set>
  2. #include<map>
  3. #include<queue>
  4. #include<stack>
  5. #include<cmath>
  6. #include<string>
  7. #include<vector>
  8. #include<cstdio>
  9. #include<cstring>
  10. #include<iostream>
  11. #include<algorithm>
  12. #define INF 1<<30
  13. #define MOD 1000000007
  14. #define ll long long
  15. #define lson l,m,rt<<1
  16. #define rson m+1,r,rt<<1|1
  17. #define pi acos(-1.0)
  18. using namespace std;
  19. const int MAXN = ;
  20. struct node{
  21. int to;
  22. int val;
  23. int next;
  24. }edge[MAXN*MAXN],edge2[MAXN*MAXN];
  25. int pre[MAXN],vis[MAXN],ind,n,m,S,T;
  26. void add(int x,int y,int z){
  27. edge2[ind].to = y;
  28. edge2[ind].val = z;
  29. edge2[ind].next = pre[x];
  30. pre[x] = ind ++;
  31. }
  32. bool bfs(int S,int T){
  33. memset(vis,-,sizeof(vis));
  34. queue<int>q;
  35. vis[S] = ;
  36. q.push(S);
  37. while(!q.empty()){
  38. int tp = q.front();
  39. q.pop();
  40. for(int i = pre[tp]; i != -; i = edge[i].next){
  41. int t = edge[i].to;
  42. if(vis[t] == - && edge[i].val){
  43. vis[t] = vis[tp] + ;
  44. q.push(t);
  45. }
  46. }
  47. }
  48. return vis[T] != -;
  49. }
  50. int dfs(int rt,int low){
  51. if(rt == T){
  52. return low;
  53. }
  54. int used = ;
  55. for(int i = pre[rt]; i != - && used < low; i = edge[i].next){
  56. int t = edge[i].to;
  57. if(vis[t] == vis[rt] + && edge[i].val){
  58. int b = dfs(t,min(low-used,edge[i].val));
  59. used += b;
  60. edge[i].val -= b;
  61. edge[i^].val += b;
  62. }
  63. }
  64. if(used == )vis[rt] = -;
  65. return used;
  66. }
  67. int dinic(int S,int T){
  68. int ans = ;
  69. while(bfs(S,T)){
  70. while(){
  71. int a = dfs(S,INF);
  72. if(a == )break;
  73. ans += a;
  74. }
  75. }
  76. return ans;
  77. }
  78. int main(){
  79. while(~scanf("%d%d",&n,&m)){
  80. if(m == ){
  81. if(n == )
  82. printf("1\n");
  83. else
  84. printf("0\n");
  85. continue;
  86. }
  87. ind = ;
  88. memset(pre,-,sizeof(pre));
  89. for(int i = ; i <= m; i++){
  90. int x,y;
  91. scanf(" (%d,%d)",&x,&y);
  92. x ++,y ++;
  93. add(x+n,y,INF),add(y,x+n,);
  94. add(y+n,x,INF),add(x,y+n,);
  95. }
  96. for(int i = ; i <= n; i++){
  97. add(i,i+n,),add(i+n,i,);
  98. }
  99. int ans = INF;
  100. for(int i = ; i <= n; i++){
  101. for(int j = ; j < ind; j++){
  102. edge[j] = edge2[j];
  103. }
  104. S = + n,T = i;
  105. ans = min(ans,dinic(S,T));
  106. }
  107. if(ans == INF)ans = n;
  108. printf("%d\n",ans);
  109. }
  110. return ;
  111. }

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. AC小笔记

    1:基本库函数的使用 Rand()函数,可以产生0~32767之间的随机数. a+rand()%(b-a)  可以得到 [a,b] 之间的随机数. 2:基本数据类型的使用 可以使用强制类型转换 例如: ...

  2. U-BOOT-Linux启动指令bootm分析

    首先说一下uImage和zImage的区别 uImage是在zImage之前加上信息头.包含系统类型.是否压缩及压缩方式等 bootm命令只能启动uImage 幻数:说得再好听的名字也只不过是个0~0 ...

  3. sublime3 常用插件

    1,emmet,html代码自动补全插件 2,jsFormat js格式化插件 3,HTMLBeautify 格式化html插件 4,autoPrefix css3自动补全前缀 5,SublimeCo ...

  4. shipyard安装

    1.Start an data volume instance of RethinkDB: # docker run -it -d --name shipyard-rethinkdb-data \ - ...

  5. checkbox与jq<转>

    题:经常使用jQuery插件的attr方法获取checked属性值,获取的值的大小为未定义,此时可以用prop方法获取其真实值,下面介绍这两种方法的区别: 1.通过prop方法获取checked属性, ...

  6. EEG: electrode positions & Broadmann atlas

    Source: http://www.brainm.com/software/pubs/dg/BA_10-20_ROI_Talairach/nearesteeg.htm   Area LEFT RIG ...

  7. HDU 1022 Train Problem I

    A - Train Problem I Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  8. [LINK]php的三种CLI常量:STDIN,STDOUT,STDERR

    FROM : http://www.cnblogs.com/thinksasa/archive/2013/02/27/2935158.html PHP CLI(command line interfa ...

  9. JavaScript操作XML

    JavaScript操作XML (一) JavaScript操作XML是通过XML DOM来完成的.那么什么是XML DOM呢?XML DOM 是: 用于 XML 的标准对象模型 用于 XML 的标准 ...

  10. SQLServer 分布式查询MySQL

    这学期开了分布式数据库这门课,开始编程实现,今天调试了一早上,写下此配置文件方便查询. 本文实现的是SQLServer2008 Express 链式添加MySql-5.6.10数据库,进行远程操作. ...