http://acm.hdu.edu.cn/showproblem.php?pid=3671

给出一幅无向图,询问有多少种移除点对的方案使得剩下的连通分量个数大于1.

和上一题差不多的思路直接做n次tarjin即可。

 #include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
#define LL long long
#define pb push_back
const int maxn=;
vector<int>g[maxn];
int dfn[maxn],low[maxn],sub[maxn],root,sum,ban;
bool vis[maxn];
void dfs(int u){
dfn[u]=low[u]=sum++;
vis[u]=;
int son=;
for(int i=;i<g[u].size();++i){
int v=g[u][i];
if(v==ban) continue;
if(vis[v]){
low[u]=min(low[u],dfn[v]);
}
else{
dfs(v);
if(u==root)son++;
else{
if(low[v]>=dfn[u])sub[u]++;
}
low[u]=min(low[u],low[v]);
}
}
if(u==root)sub[u]=son;
else sub[u]++;
}
int main(){
int n,m,cas=,i,j,u,v;
while(scanf("%d%d",&n,&m)==){
if(n==&&m==)break;
for(i=;i<=n;++i)g[i].clear();
while(m--){
scanf("%d%d",&u,&v);
g[u].pb(v);
g[v].pb(u);
}
int ans=;
for(i=;i<=n;++i){
int p=;
ban=i,sum=;
memset(vis,,sizeof(vis));
memset(sub,,sizeof(sub));
for(j=;j<=n;++j){
if(j==ban || vis[j]) continue;
root=j;
p++;
dfs(j);
}
//cout<<"p="<<p<<endl;
for(j=i+;j<=n;++j){
if(sub[j]+p->=)ans++;
}
}
printf("Case %d: %d\n",++cas,ans);
}
return ;
}

hdu-3671-tarjin/割点方案的更多相关文章

  1. HDU - 3671 Boonie and Clyde (图的割点)

    As two icons of the Great Depression, Bonnie and Clyde represent the ultimate criminal couple. Stori ...

  2. POJ 2117 (割点+连通分量)

    题目链接: http://poj.org/problem?id=2117 题目大意:在一个非连通图中,求一个切除图中任意一个割点方案,使得图中连通分量数最大. 解题思路: 一个大陷阱,m可以等于0,这 ...

  3. Tarjan总结(缩点+割点(边)+双联通+LCA+相关模板)

    Tarjan求强连通分量 先来一波定义 强连通:有向图中A点可以到达B点,B点可以到达A点,则称为强连通 强连通分量:有向图的一个子图中,任意两个点可以相互到达,则称当前子图为图的强连通分量 强连通图 ...

  4. tarjin求割点

    题目: hdu3671 http://acm.hdu.edu.cn/showproblem.php?pid=3671 题意:给一个无向图,要求毁掉两个点,使图变得不连通,图一开始是连通的 因为要毁掉两 ...

  5. HDU 1026 (BFS搜索+优先队列+记录方案)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1026 题目大意:最短时间内出迷宫.迷宫里要杀怪,每个怪有一定HP,也就是说要耗一定时.输出方案. 解 ...

  6. HDU 4587 TWO NODES 割点

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意: 删除两个点,使连通块的数目最大化 题解: 枚举删除第一个点,然后对删除了第一个点的图跑 ...

  7. hdu 5739 割点

    Fantasia Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  8. hdu 2126 Buy the souvenirs 二维01背包方案总数

    Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. HDU 2126 01背包(求方案数)

    Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. 论文笔记: Dual Deep Network for Visual Tracking

    论文笔记: Dual Deep Network for Visual Tracking  2017-10-17 21:57:08  先来看文章的流程吧 ... 可以看到,作者所总结的三个点在于: 1. ...

  2. Images之base image

    Create a base image Most Dockerfiles start from a parent image. If you need to completely control th ...

  3. error: could not create '/System/Library/Frameworks/Python.framework/Versions/2.7/share': Operation not permitted

    参考: Python pip安装模块报错 Mac升级到EI Captain之后pip install 无法使用问题 error: could not create '/System/Library/F ...

  4. 最小 base64 图片

    http://www.webhek.com/post/base64-encode-of-1x1px-transparent-gif.html Base64 Encode 1x1px透明GIF图片 Ba ...

  5. C#接口的作用详解

    .C#接口的作用 : C#接口是一个让很多初学C#者容易迷糊的东西,用起来好像很简单,定义接口,里面包含方法,但没有方法具体实现的代码,然后在继承该接口的类里面要实现接口的所有方法的代码,但没有真正认 ...

  6. HDU 1251 统计难题(字典树模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...

  7. JS相关重点知识 (概况)

    1.value和innerHTML没有联系,只是value是表单的一个特有属性,而innerHTML是通用的. 2.当从外部引入js文件时,该外部文件里面可以有多个方法,   html页面中的oncl ...

  8. Winform 设置控件值

    private void SetControlValue(Control control, object value) { try { control.FindForm().Invoke((Actio ...

  9. Chrome,你这坑人的默认非安全端口

    今天用chrome打开页面的发现一个错误: ERR_UNSAFE_PORT 字面意思是error:不安全端口. 一.什么是默认非安全端口?    每个浏览器出于安全问题,都会禁止一些网络浏览以外的端口 ...

  10. Educational Codeforces Round 23 F. MEX Queries 离散化+线段树

    F. MEX Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...