As two icons of the Great Depression, Bonnie and Clyde represent the ultimate criminal couple. Stories were written, headlines captured, and films were made about the two bank robbers known as Romeo and Juliet in a getaway car.

The new generation of Bonnie and Clyde is no longer cold-blooded killers with guns. Due to the boom of internet, they turn to online banks and scheme to hack the safety system. The safety system consists of a number of computers connected by bidirectional cables. Since time is limited, they decide that they will attack exactly two computers A and B in the network, and as a result, other computers won't be able to transmit messages via A and B . The attack is considered successful if there are at least two computers (other than A and B ) that disconnected after the attack.

As they want to minimize the risk of being captured, they need to find the easiest way to destroy the safety system. However, a brief study of the network indicates that there are many ways to achieve their objective; therefore they kidnapped the computer expert, you, to help with the calculation. To simplify the problem, you are only asked to tell them how many ways there are to destroy the safety system.

InputThere are multiple test cases in the input file. Each test case starts with two integers N (3<=N<=1000) and M (0<=M<=10000) , followed by M lines describing the connections between the N computers. Each line contains two integers A , B (1<=A, B<=N) , which indicates that computer A and B are connected by a bidirectional cable.

There is a blank line between two successive test cases. A single line with N = 0 and M = 0 indicates the end of input file.OutputFor each test case, output one integer number representing the ways to destroy the safety system in the format as indicated in the sample output.Sample Input

  1. 4 4
  2. 1 2
  3. 2 3
  4. 3 4
  5. 4 1
  6.  
  7. 7 9
  8. 1 2
  9. 1 3
  10. 2 3
  11. 3 4
  12. 3 5
  13. 4 5
  14. 5 6
  15. 5 7
  16. 6 7
  17.  
  18. 0 0

Sample Output

  1. Case 1: 2
  2. Case 2: 11
  3.  
  4. 题意:
    删除两个点,使图不联通,求方案数.
    思路:
    枚举第一个点,用割点判断第二点就行了.
    注意删除第一个点之后剩下联通块内部点的个数为1的情况.
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<stack>
  5. #include<queue>
  6. #include<map>
  7. #include<set>
  8. #include<cstdio>
  9. #include<cstring>
  10. #include<cmath>
  11. #include<ctime>
  12.  
  13. #define fuck(x) cerr<<#x<<" = "<<x<<endl;
  14. #define debug(a, x) cerr<<#a<<"["<<x<<"] = "<<a[x]<<endl;
  15. #define ls (t<<1)
  16. #define rs ((t<<1)|1)
  17. using namespace std;
  18. typedef long long ll;
  19. typedef unsigned long long ull;
  20. const int maxn = ;
  21. const int maxm = ;
  22. const int inf = 0x3f3f3f3f;
  23. const ll Inf = ;
  24. const int mod = ;
  25. const double eps = 1e-;
  26. const double pi = acos(-);
  27.  
  28. int Head[maxn],cnt;
  29. struct edge{
  30. int Next,v;
  31. }e[maxm];
  32. void add_edge(int u,int v){
  33. e[cnt].Next=Head[u];
  34. e[cnt].v=v;
  35. Head[u]=cnt++;
  36. }
  37.  
  38. int Index = ;
  39. int dfn[maxn], low[maxn], root;
  40. bool vis[maxn];
  41. int exc,num;
  42. void dfs(int cur, int father) {
  43. if(cur==exc){ return;}
  44. num++;
  45. int child = ;
  46. Index++;
  47. dfn[cur] = Index;
  48. low[cur] = Index;
  49. for (int k = Head[cur]; k != -; k = e[k].Next) {
  50. if(e[k].v==exc){ continue;}
  51. if (dfn[e[k].v] == ) {
  52. child++;
  53. dfs(e[k].v, cur);
  54. low[cur] = min(low[cur], low[e[k].v]);
  55. if (cur != root && low[e[k].v] >= dfn[cur]) {
  56. if(!vis[cur]){
  57. vis[cur]=true;
  58. }
  59. }
  60. if (cur == root && child == ) {
  61. if(!vis[cur]){
  62. vis[cur]=true;
  63. }
  64. }
  65. } else if (e[k].v != father) {
  66. low[cur] = min(low[cur], dfn[e[k].v]);
  67. }
  68. }
  69. }
  70.  
  71. int main() {
  72. // ios::sync_with_stdio(false);
  73. // freopen("in.txt", "r", stdin);
  74.  
  75. int n,m;
  76. int cases=;
  77. while (scanf("%d%d",&n,&m)!=EOF&&(n||m)){
  78. cases++;
  79. exc=cnt=Index=;
  80. memset(Head,-, sizeof(Head));
  81. memset(dfn,,sizeof(dfn));
  82. memset(vis,,sizeof(vis));
  83. for(int i=;i<=m;i++){
  84. int x,y;
  85. scanf("%d%d",&x,&y);
  86. add_edge(x,y);
  87. add_edge(y,x);
  88. }
  89.  
  90. int ans=;
  91. for(int i=;i<=n;i++) {
  92. memset(dfn, , sizeof(dfn));
  93. memset(vis, , sizeof(vis));
  94. Index=;
  95. exc = i;
  96. int d1,d2;
  97. int tot = ;
  98. dfn[exc]=-;
  99. d1=d2=-;
  100. for(int j=;j<=n;j++){
  101. if(!dfn[j]&&j!=exc){
  102. tot++;
  103. root=j;
  104. num=;
  105. dfs(j,j);
  106. if(d1==-)d1=num;
  107. else d2=num;
  108. }
  109. }
  110. if(tot==){//如果删除的点不是割点,那么和它组合的一定是割点(删除之后)
  111. for(int j=;j<=n;j++){
  112. ans+=vis[j];
  113. }
  114. }else if(tot==){//这个点是割点,而且把原图分为了两部分
  115. if(d1==d2&&d1==){
  116. ans+=;
  117. }//如果两部分的点数都是1,那么对答案没有贡献
  118. else if(d1==||d2==){ans+=n-;}//有一个是1,就不能删除那个独苗
  119. else ans+=n-;//既然都不是1,那就可以随便删除
  120. }else{
  121. ans+=n-;//有三块,可以任意删除
  122. }
  123. }printf("Case %d: %d\n",cases,ans/);
  124.  
  125. }
  126.  
  127. return ;
  128. }

HDU - 3671 Boonie and Clyde (图的割点)的更多相关文章

  1. 图的割点 | | jzoj【P1230】 | | gdoi | |备用交换机

    写在前面:我真的不知道图的割点是什么.... 看见ftp图论专题里面有个dfnlow的一个文档,于是怀着好奇的心情打开了这个罪恶的word文档,,然后就开始漫长的P1230的征讨战.... 图的割点是 ...

  2. 图的割点 桥 双连通(byvoid)

    [点连通度与边连通度] 在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成多个连通块,就称这个点集为割点集合.一个图的点连通度的定义为,最小割点集 ...

  3. Tarjan算法:求解图的割点与桥(割边)

    简介: 割边和割点的定义仅限于无向图中.我们可以通过定义以蛮力方式求解出无向图的所有割点和割边,但这样的求解方式效率低.Tarjan提出了一种快速求解的方式,通过一次DFS就求解出图中所有的割点和割边 ...

  4. Tarjan算法:求解无向连通图图的割点(关节点)与桥(割边)

    1. 割点与连通度 在无向连通图中,删除一个顶点v及其相连的边后,原图从一个连通分量变成了两个或多个连通分量,则称顶点v为割点,同时也称关节点(Articulation Point).一个没有关节点的 ...

  5. HDU - 4587 TWO NODES (图的割点)

    Suppose that G is an undirected graph, and the value of stab is defined as follows: Among the expres ...

  6. HDU 1045 Fire Net(图匹配)

    题目大意: 这个是以前做过的一道DFS题目,当时是完全暴力写的. 给你一个N代表是N*N的矩阵,矩阵内 ‘X’代表墙, ‘.’代表通道. 问这个矩阵内最多可以放几个碉堡, 碉堡不能在同一行或者同一列, ...

  7. HDU 4444 Walk (离散化建图+BFS+记忆化搜索) 绝对经典

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4444 题意:给你一些n个矩形,给你一个起点,一个终点,要你求从起点到终点最少需要转多少个弯 题解:因为 ...

  8. hdu 3061 hdu 3996 最大权闭合图 最后一斩

    hdu 3061 Battle :一看就是明显的最大权闭合图了,水提......SB题也不说边数多少....因为开始时候数组开小了,WA....后来一气之下,开到100W,A了.. hdu3996. ...

  9. hdu 4738 Caocao's Bridges 图--桥的判断模板

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. MongoDB负载信息一目了然 阿里云HDM重磅发布MongoDB监控和诊断功能

    混合云数据库管理(HDM)的统一监控.告警.诊断功能新增了对MongoDB的支持. 通过直观的方式将MongoDB多个维度的负载信息统一整合,不仅可以清晰的查看实时负载信息,也可以方便的确认历史负载情 ...

  2. [自考]C++中一些特殊用法 2016-10-16 22:12 318人阅读 评论(30) 收藏

    做了一段时间的C++的试题了,总结一些这段时间经常犯错和需要注意的地方. 一.常用的保留字和符号 const 定义常量或者参数 void 定义空类型变量或空类型指针,或指定函数没有返回值 static ...

  3. qt .pro文件和cmakelists.txt配置第三方库

    .pro文件引用第三方库文件和头文件路径 1.库文件(LIBS添加的是共享库文件,-L添加目录,-l指定共享库名称) LIBS += -L/usr/local/lib -lmath LIBS的使用就是 ...

  4. 洛谷2387 BZOJ3669魔法森林题解

    题目链接 BZ链接 这道题被很多人用spfa水了过去,表示很... 其实spfa很好卡,这组数据可以卡掉大多数spfa 链接:密码:rjvk 这里讲一下LCT的做法 我们按照a将边排序,然后依次添加 ...

  5. LeetCode103 Binary Tree Zigzag Level Order Traversal

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...

  6. dnspython

    dnspython 一个Python实现的一个DNS工具包,利用其查询功能来实现dns的服务监控及解析结果的校验. 安装 pip install dnspython 解析域名为IP from dns ...

  7. iOS 9适配系列教程:后台定位

    http://www.cocoachina.com/ios/20150624/12200.html Demo:GitHub地址 [iOS9在定位的问题上,有一个坏消息一个好消息]坏消息:如果不适配iO ...

  8. Java练习 SDUT-1131_最大公约数与最小公倍数

    C/C++训练1---最大公约数与最小公倍数 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 输入两个正整数,求它们的最 ...

  9. UVa-10986_Sending email (向前星+Dijkstra)

    题意:给你点.边,求起点到终点的最短距离. 题解:由于题目的数据量特别大,所以需要用邻接表来存边,之后对Dijkstra算法稍微魔改一下就可以了,本来以为会超时,做好了打堆优化的准备,结果卡时间过了, ...

  10. 阿里云:面向5G时代的物联网无线连接服务

    在4月24日落幕的2019中国联通合作伙伴大会“5G+物联网(IoT)论坛”上,阿里云高级运营专家李茁出席圆桌对话,分享了5G时代物联网如何更好地推动行业完成生产.管理和商业模式的创新,阿里云又会以何 ...