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 ...
随机推荐
- DataGridView 操作
//dataGridView 删除选中行 int num = dataGridView2.SelectedRows.Count; ) { DataGridViewRow r = dataGridVie ...
- 路由器之VPN应用与配置指南
应用背景 近日,公司需要在外人员通过直接访问连接到公司内网,实现办公等一系列操作,这个时候就需要通过配置路由器VPN实现该需求了. 无线企业路由器可以帮助中小型企业搭建高性价比.稳定的企业办公网络,灵 ...
- libjpeg 交叉编译动态库和静态库
1.下载libjpeg库,解压之 得到了jpeg6b和libtool-2.2.4两个文件夹. 2.编译安装libtool工具. 这是配置libtool,这里需要注意:configure 参 ...
- (转)RabbitMQ消息队列(七):适用于云计算集群的远程调用(RPC)
在云计算环境中,很多时候需要用它其他机器的计算资源,我们有可能会在接收到Message进行处理时,会把一部分计算任务分配到其他节点来完成.那么,RabbitMQ如何使用RPC呢?在本篇文章中,我们将会 ...
- DBCP之----"数据库"与"连接池"的连接建立过程
1 public class DBCPTest { 2 /* 3 * 使用BasicDataSource类,通过url, 4 和diverClass,username,password, 5 几个参数 ...
- hdu 1203 I NEED A OFFER (0-1背包)
题意分析:0-1背包变形 递推公式:dp[i] = max(dp[i], 1-(1-dp[i-C])*(1-p)) /* I NEED A OFFER! Time Limit: 2000/1000 ...
- ubuntu 常用参数设置
在Linux下,对于参数的设置,一般来说,都遵循这个规律.每一个功能程序,一定对于一个对于名字的配置文件. 涉及到多用户的功能配置,一定有一个全局的配置文件,对所有用户都生效,而每个用 ...
- float,double和decimal的精度问题
先标注一个音标,因为我老是读错:decimal ['desɪml] 精度对比: 类型 CTS 类型 描述 有效数字 范围 float System.Single 32-bit single-preci ...
- Microsoft.Xna.Framework.TitleContainer.OpenStream()
/// <summary> /// This method opens a file using System.IO classes and the /// TitleLocation p ...
- ◆linux分区的加密与自动解密◆——Super孟再创辉煌
首先制作分区的加密挂载: 分区的自动解密: