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

4 4
1 2
2 3
3 4
4 1 7 9
1 2
1 3
2 3
3 4
3 5
4 5
5 6
5 7
6 7 0 0

Sample Output

Case 1: 2
Case 2: 11 题意:
删除两个点,使图不联通,求方案数.
思路:
枚举第一个点,用割点判断第二点就行了.
注意删除第一个点之后剩下联通块内部点的个数为1的情况.
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime> #define fuck(x) cerr<<#x<<" = "<<x<<endl;
#define debug(a, x) cerr<<#a<<"["<<x<<"] = "<<a[x]<<endl;
#define ls (t<<1)
#define rs ((t<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int maxm = ;
const int inf = 0x3f3f3f3f;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); int Head[maxn],cnt;
struct edge{
int Next,v;
}e[maxm];
void add_edge(int u,int v){
e[cnt].Next=Head[u];
e[cnt].v=v;
Head[u]=cnt++;
} int Index = ;
int dfn[maxn], low[maxn], root;
bool vis[maxn];
int exc,num;
void dfs(int cur, int father) {
if(cur==exc){ return;}
num++;
int child = ;
Index++;
dfn[cur] = Index;
low[cur] = Index;
for (int k = Head[cur]; k != -; k = e[k].Next) {
if(e[k].v==exc){ continue;}
if (dfn[e[k].v] == ) {
child++;
dfs(e[k].v, cur);
low[cur] = min(low[cur], low[e[k].v]);
if (cur != root && low[e[k].v] >= dfn[cur]) {
if(!vis[cur]){
vis[cur]=true;
}
}
if (cur == root && child == ) {
if(!vis[cur]){
vis[cur]=true;
}
}
} else if (e[k].v != father) {
low[cur] = min(low[cur], dfn[e[k].v]);
}
}
} int main() {
// ios::sync_with_stdio(false);
// freopen("in.txt", "r", stdin); int n,m;
int cases=;
while (scanf("%d%d",&n,&m)!=EOF&&(n||m)){
cases++;
exc=cnt=Index=;
memset(Head,-, sizeof(Head));
memset(dfn,,sizeof(dfn));
memset(vis,,sizeof(vis));
for(int i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
add_edge(x,y);
add_edge(y,x);
} int ans=;
for(int i=;i<=n;i++) {
memset(dfn, , sizeof(dfn));
memset(vis, , sizeof(vis));
Index=;
exc = i;
int d1,d2;
int tot = ;
dfn[exc]=-;
d1=d2=-;
for(int j=;j<=n;j++){
if(!dfn[j]&&j!=exc){
tot++;
root=j;
num=;
dfs(j,j);
if(d1==-)d1=num;
else d2=num;
}
}
if(tot==){//如果删除的点不是割点,那么和它组合的一定是割点(删除之后)
for(int j=;j<=n;j++){
ans+=vis[j];
}
}else if(tot==){//这个点是割点,而且把原图分为了两部分
if(d1==d2&&d1==){
ans+=;
}//如果两部分的点数都是1,那么对答案没有贡献
else if(d1==||d2==){ans+=n-;}//有一个是1,就不能删除那个独苗
else ans+=n-;//既然都不是1,那就可以随便删除
}else{
ans+=n-;//有三块,可以任意删除
}
}printf("Case %d: %d\n",cases,ans/); } return ;
}

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. More Effective C++: 03异常

    C++的异常机制使得程序付出某些代价:资源泄漏的可能性增加了:写出具有你希望的行为的构造函数与析构函数变得更加困难:执行程序和库程序尺寸增加了,同时运行速度降低了等等. 但是为什么使用异常呢?C程序使 ...

  2. JAVA高级特性--String/StringBuffer/Builder

    String String对象一旦创建就不能改变 是常量 需要进行大量字符串操作应采用StringBuffer/StringBuilder  最终结果转换成String对象 StringBuffer ...

  3. Java练习 SDUT-2561_九九乘法表

    九九乘法表 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 九九乘法表是数学学习的基础,今天我们就来看看乘法表的相关问题 ...

  4. HZOJ Silhouette

    转化一下题意:给出矩阵每行每列的最大值,求满足条件的矩阵个数. 先将A,B按从大到小排序,显然没有什么影响.如果A的最大值不等于B的最大值那么无解否则一定有解. 考虑从大到小枚举A,B中出现的数s,那 ...

  5. wepy —— 组件之间通信

    一.props 1.静态传值 —— 父组件向子组件传递常量数据 // 父组件 <coma fruitName="橘子"></coma> // 子组件 // ...

  6. python-selenium自动化测试(火狐、谷歌、360浏览器启动)

    一.打开谷歌浏览器 import selenium from selenium import webdriver browser = webdriver.Chrome(executable_path ...

  7. oracle函数 chartorowid(c1)

    [功能]转换varchar2类型为rowid值 [参数]c1,字符串,长度为18的字符串,字符串必须符合rowid格式 [返回]返回rowid值 [示例] SELECT chartorowid('AA ...

  8. oracle函数 SOUNDEX(c1)

    [功能]返回字符串参数的语音表示形式 [参数]c1,字符型 [返回]字符串 [说明]相对于比较一些读音相同,但是拼写不同的单词是非常有用的. 计算语音的算法: 1.保留字符串首字母,但删除a.e.h. ...

  9. Project Euler Problem 23-Non-abundant sums

    直接暴力搞就行,优化的地方应该还是计算因子和那里,优化方法在这里:http://www.cnblogs.com/guoyongheng/p/7780345.html 这题真坑,能被写成两个相同盈数之和 ...

  10. Websocket 群聊功能

    websocket 群聊 前提关闭防火墙 写入代码 from flask import Flask,request,render_template from geventwebsocket.handl ...