题目链接:

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 割点的更多相关文章

  1. HDU 4587 TWO NODES 枚举+割点

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 TWO NODES Time Limit: 24000/12000 MS (Java/Other ...

  2. HDU - 4587 TWO NODES (图的割点)

    Suppose that G is an undirected graph, and the value of stab is defined as follows: Among the expres ...

  3. 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 ...

  4. HDU 4587 TWO NODES(割两个点的最大连通分支数)

    http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意: 给一图,求割去两个点后所能形成的最大连通分支数. 思路: 对于这种情况,第一个只能枚举,然后在删除 ...

  5. hdu 4587(割点的应用)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 思路:题目的意思很简单,就是删除任意2个节点以及关联的边,求图的最大连通分量数.我们知道删除割点 ...

  6. hdu 4587 推断孤立点+割点+ 删除点之后,剩下多少连通分量

    做了非常久...... 题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=4587 先枚举删除的第一个点,第二个点就是找割点.没有割点当然也有答案 学到 ...

  7. HDU 4587 B - TWO NODES tarjan

    B - TWO NODESTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  8. hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。

    题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...

  9. 【HDOJ】4587 TWO NODES

    Tarjan解无向图的割点和桥,参考白书. /* 4587 */ #include <iostream> #include <vector> #include <algo ...

随机推荐

  1. iOS使用keychain存储密码

    iOS设备中的Keychain是一个安全的存储容器.通常情况下,可以用NSUserDefaults存储数据信息,但是对于一些私密信息,比如账号.密码等等,就需要使用更为安全的keychain了.苹果自 ...

  2. (转)Yale CAS + .net Client 实现 SSO(3)

    第一部分:安装配置 Tomcat 第二部分:安装配置 CAS 第三部分:实现 ASP.NET WebForm Client 1. 下载.NET CAS client. .NET CAS Client ...

  3. Ueditor 1.4.3 单独调用上传图片,或文件功能

    第一步, 引入文件 <script src="ueditor/ueditor.config.js" type="text/javascript" char ...

  4. BZOJ 1631==USACO 2007== POJ 3268 Cow Party奶牛派对

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19226   Accepted: 8775 Description One ...

  5. windows phone 8 开发系列(一)环境搭建

    一:前奏说明 本人一名普通的neter,对新玩意有点小兴趣,之前wp7出来的时候,折腾学习过点wp7开发,后来也没怎么用到(主要对微软抛弃wp7的行为比较不爽),现在wp8已经出来一段时间了,市场上也 ...

  6. 封装cookie

    function cookie(name,value,expires){ switch(typeof value){ case 'string': //设置 var exp=''; if(expire ...

  7. 深入解析PHP 5.3.x 的strtotime() 时区设定 警告信息修复

    在某些参考资料中是说这两个方法任选其一就可,但经我测试,必须两个方法同时使用,才不会再出现错误提示 PHP Warning: strtotime(): It is not safe to rely o ...

  8. iphone document 图片存储和读取

    转载自:http://longquan.iteye.com/blog/1669990 存: //此处首先指定了图片存取路径(默认写到应用程序沙盒 中) NSArray *paths = NSSearc ...

  9. .NET SDK和下载

    http://blogs.msdn.com/b/dotnet/p/dotnet_sdks.aspx .NET SDK和下载 您可以通过下载.NET框架针对包和软件开发工具包,并使用它们与Visual ...

  10. uploadify 上传

    本来想做一套上传公用的组建的,里面包含文件转码等功能,看来这些都只能后来一步一步加上了,先写下来... 1,引入脚本等 @{ Layout = null; } <!DOCTYPE html> ...