HDU 4587 TWO NODES 割点
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4587
题意:
删除两个点,使连通块的数目最大化
题解:
枚举删除第一个点,然后对删除了第一个点的图跑割点更新答案。
代码:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std; const int maxn = ;
vector<int> G[maxn]; int n,m; int pre[maxn], low[maxn], iscut[maxn], dfs_clock;
int dfs(int u, int fa,int tag) {
int lowu = pre[u] = ++dfs_clock;
int child = ;
for (int i = ; i < G[u].size(); i++) {
int v = G[u][i];
if (v == tag||v==fa) continue;
if (!pre[v]) {
child++;
int lowv = dfs(v, u, tag);
lowu = min(lowu, lowv);
if (lowv >= pre[u]) {
iscut[u]++;
}
}
else if (pre[v] < pre[u] && v != fa) {
lowu = min(lowu, pre[v]);
}
}
if (fa < && child == ) iscut[u]--;
else if (fa < ) iscut[u]--;
low[u] = lowu;
return lowu;
} void init() {
for (int i = ; i < n; i++) G[i].clear();
} int main() {
while (scanf("%d%d", &n, &m) == && n) {
init();
for (int i = ; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
int ans = -;
for (int i = ; i < n; i++) {
memset(pre, , sizeof(pre));
memset(iscut, , sizeof(iscut));
dfs_clock = ;
int cnt = ;
for (int j = ; j<n; j++) {
if (j == i) continue;
if (!pre[j]) {
cnt++;
dfs(j, -, i);
}
}
for (int j = ; j < n; j++) {
if (j == i) continue;
ans = max(ans, iscut[j] + cnt);
}
}
printf("%d\n", ans);
}
return ;
}
HDU 4587 TWO NODES 割点的更多相关文章
- HDU 4587 TWO NODES 枚举+割点
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 TWO NODES Time Limit: 24000/12000 MS (Java/Other ...
- HDU - 4587 TWO NODES (图的割点)
Suppose that G is an undirected graph, and the value of stab is defined as follows: Among the expres ...
- HDU 4587 TWO NODES(割点)(2013 ACM-ICPC南京赛区全国邀请赛)
Description Suppose that G is an undirected graph, and the value of stab is defined as follows: Amon ...
- HDU 4587 TWO NODES(割两个点的最大连通分支数)
http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意: 给一图,求割去两个点后所能形成的最大连通分支数. 思路: 对于这种情况,第一个只能枚举,然后在删除 ...
- hdu 4587(割点的应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 思路:题目的意思很简单,就是删除任意2个节点以及关联的边,求图的最大连通分量数.我们知道删除割点 ...
- hdu 4587 推断孤立点+割点+ 删除点之后,剩下多少连通分量
做了非常久...... 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4587 先枚举删除的第一个点,第二个点就是找割点.没有割点当然也有答案 学到 ...
- HDU 4587 B - TWO NODES tarjan
B - TWO NODESTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。
题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...
- 【HDOJ】4587 TWO NODES
Tarjan解无向图的割点和桥,参考白书. /* 4587 */ #include <iostream> #include <vector> #include <algo ...
随机推荐
- 收集一些常用的php正则表达式
1. 平时做网站经常要用正则表达式,下面是一些讲解和例子,仅供大家参考和修改使用: 2. "^\d+$" //非负整数(正整数 + 0) 3. "^[0 ...
- JavaScript学习笔记 - 进阶篇(2)- 数组
什么是数组 我们知道变量用来存储数据,一个变量只能存储一个内容.假设你想存储10个人的姓名或者存储20个人的数学成绩,就需要10个或20个变量来存储,如果需要存储更多数据,那就会变的更麻烦.我们用数组 ...
- 对象this、currentTarget和target
在事件处理程序内部,对象this始终等于currentTarget的值,而target则只包含事件的实际目标.如果直接将事件处理程序指定给了目标元素,则this.currentTarget和targe ...
- JAVA(int...i)问题
第一次看到这种写法,弄不明白到底会是神马结果,运行后才发现是这么的神奇. 无论你调用的方法中带几位参数,“hello”一直可以被输出.
- think in java 第四版读书笔记 第一章对象导论
很久没有碰过java了,为了项目需要以及以后找工作,还是有必要将think in java通读一遍.欢迎大家一起讨论学习 1.1抽象过程 面向对象语言的5个特性: 1.万物皆对象 任何事物都可以抽象为 ...
- sort()的多种用法
sort() 方法用于对数组的元素进行排序. 一.默认情况 在默认情况下, sort() 方法按升序排列数组项.为了实现排序, sort() 方法会调用每个数组项的 toString() 转型方法, ...
- shiro错误No SecurityManager accessible to the calling code
Shire在Web.xml中shiroFilter的Mapping配置错误 org.apache.shiro.UnavailableSecurityManagerException: No Secur ...
- VMWare 不能识别SD卡
打开service
- corosync+pacemaker实现高可用(HA)集群
corosync+pacemaker实现高可用(HA)集群(一) 重要概念 在准备部署HA集群前,需要对其涉及的大量的概念有一个初步的了解,这样在实际部署配置时,才不至于不知所云 资源.服务与 ...
- mysql-5.5.46源码编译安装
1.安装准备 cat /etc/redhat-release uname -r yum install ncurses-devel cmake automake autoconf make gcc g ...