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. (zhuan) Attention in Long Short-Term Memory Recurrent Neural Networks

    Attention in Long Short-Term Memory Recurrent Neural Networks by Jason Brownlee on June 30, 2017 in  ...

  2. Python 爬虫常用的库

    一.常用库 1.requests 做请求的时候用到. requests.get("url") 2.selenium 自动化会用到. 3.lxml 4.beautifulsoup 5 ...

  3. json扩展

    using Newtonsoft.Json.Linq; namespace Utility { public static class JsonExt { /// <summary> // ...

  4. dml语句和ddl语句 区别

    delete from user删除所有记录,属于dml语句,一条记录一条记录删除.事务可以作用在dml语句上的 truncate table user;删除所有记录,属于ddl语句,将表删除,然后重 ...

  5. maven 打包不同环境

    支持不同环境打包 1 pom添加如下配置: 1)添加指定打包id 区分各个环境 <profiles> <profile> <id>dev</id> &l ...

  6. Ubuntu 编译安装 Xdebug

    安装xdebug 1.下载 https://xdebug.org/download.php 找到PHP5.6对应的版本 https://xdebug.org/files/xdebug-2.5.5.tg ...

  7. label和span的区别

    label标签主要用于绑定一个表单元素,当点击label标签的时候,被绑定的表单元素就会获得输入焦点. <div class="form-group col-lg-12"&g ...

  8. ado_基本连接操作【四】

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data. ...

  9. MsgWaitForMultipleObjects_测试

    1.个人感觉: 1.1.MSDN中(https://msdn.microsoft.com/en-us/library/ms684242.aspx),说: “ dwWakeMask [in] The i ...

  10. mysql 清空表——truncate 与delete的区别

    清空表 truncate table [表名]: delete from [表名]: 注: truncate是整体删除(速度较快), delete是逐条删除(速度较慢). truncate不写服务器l ...