HDU 4587 B - TWO NODES tarjan
B - TWO NODES
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87326#problem/B
Description
Among the expression,G -i, -j is the remainder after removing node i, node j and all edges that are directly relevant to the previous two nodes. cntCompent is the number of connected components of X independently.
Thus, given a certain undirected graph G, you are supposed to calculating the value of stab.
Input
Please note that the endpoints of edge is marked in the range of [0,N-1], and input cases ends with EOF.
Output
For each graph in the input, you should output the value of stab.
Sample Input
4 5
0 1
1 2
2 3
3 0
0 2
Sample Output
2
HINT
题意
一个图,让你删除两个点之后,连通块最多有多少个
题解:
枚举第一个点,然后跑tarjan求割点就好了
代码:
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int N=;
int dfn[N],low[N],pre[N],to[N],nxt[N],vis[N],sum[N],cnt,tm,ans,tot,ret,aim,n,m; void makeedge(int a,int b)
{
to[cnt]=a;nxt[cnt]=pre[b];pre[b]=cnt++;
to[cnt]=b;nxt[cnt]=pre[a];pre[a]=cnt++;
return ;
} void dfs(int x,int fa)
{
dfn[x]=tm;
low[x]=tm++;
vis[x]=;
sum[x]=;
for(int p=pre[x];p!=-;p=nxt[p])
{
if(to[p]!=aim&&to[p]!=fa)
{
int y=to[p];
if(!vis[y])
{
vis[y]=;
dfs(y,x);
low[x]=min(low[y],low[x]);
if(low[y]>=dfn[x]) sum[x]++;
}
else
{
low[x]=min(low[x],dfn[y]);
}
}
}
if(x==fa) sum[x]--;
if(ans<sum[x]) ans=sum[x];
return ;
} void solve()
{
ans=-;tot=;
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
if(!vis[i]&&i!=aim)
{
tm=;
dfs(i,i);
tot++;
}
if(ret<ans+tot+) ret=ans+tot+;
// cout<<ans<<" "<<tot<<" "<<ans+tot+2<<endl;
return ;
} int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(pre,-,sizeof(pre));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(vis,,sizeof(vis));
memset(sum,,sizeof(sum));
cnt=;ans=;tot=;tm=;ret=;
for(int i=;i<=m;i++)
{
int a,b;
scanf("%d%d",&a,&b);
a++,b++;
makeedge(a,b);
}
for(int i=;i<=n;i++)
{
aim=i;
solve();
}
printf("%d\n",ret-);
}
return ;
}
HDU 4587 B - TWO NODES tarjan的更多相关文章
- 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(割两个点的最大连通分支数)
http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意: 给一图,求割去两个点后所能形成的最大连通分支数. 思路: 对于这种情况,第一个只能枚举,然后在删除 ...
- HDU 4587 TWO NODES 割点
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意: 删除两个点,使连通块的数目最大化 题解: 枚举删除第一个点,然后对删除了第一个点的图跑 ...
- 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 (图的割点)
Suppose that G is an undirected graph, and the value of stab is defined as follows: Among the expres ...
- hdu 4738 Caocao's Bridges (tarjan求桥)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题目大意:给一些点,用一些边把这些点相连,每一条边上有一个权值.现在要你破坏任意一个边(要付出相 ...
- HDU 3969 Hawk-and-Chicken(dfs+tarjan缩点优化,网上最详细解析!!!)
Hawk-and-Chicken Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4635 Strongly connected (Tarjan+一点数学分析)
Strongly connected Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) ...
- hdu 4587(割点的应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 思路:题目的意思很简单,就是删除任意2个节点以及关联的边,求图的最大连通分量数.我们知道删除割点 ...
随机推荐
- 用defy来潜水最终还是挂了........
defy526是6级,,不过好像这次我用来潜过去不足2米还是挂掉了... 国际通用的防水级别认证体系: IPX-0 没有防水保护 IPX-1 设备在正常操作状态下,可以提供相当于3-5毫米/分钟降雨的 ...
- MyBatis学习 之 二、SQL语句映射文件(1)resultMap
目录(?)[-] 二SQL语句映射文件1resultMap resultMap idresult constructor association联合 使用select实现联合 使用resultMap实 ...
- Android中TabHost嵌套TabHost
在嵌套TabHost时,先后遇到了以下情况: 问题1:内部TabHos无显示,只显示了其中的一个Activity: 解决:按下文比对主子TabHos的布局文件和java文件并修改: 问题2:如上所做后 ...
- ubuntu下安装selenium2.0 环境
参考:http://www.cnblogs.com/fnng/archive/2013/05/29/3106515.html ubuntu 安装过程: 1.安装:setuptools $ apt-ge ...
- [原创]谷歌插件 - YE搜图助手(YeImageFinder)
最新版本:下载 版本:v1.5 更新时间:2014年10月08日 +完善了:YeImageFinder:支持在每次启用插件时,也能正常绑定右键! +完善了:每次做完动作后,就马上关闭自身! 版本:v ...
- VS2010下 LibVLC开发环境搭建
LibVLC环境的搭建 最近又 LIBVLC 做一个视频播放器,封装成ActiveX控件,之前做过一个基于OpenCV的播放器(只解码视频,音频不用,OpenCV也没有解码音频的功能). 到目前位置 ...
- LeetCode题解——Longest Common Prefix
题目: 给定一系列的字符串,找出这些字符串的最长公共前缀. 解法: 暴力法,依次比较每个字符串的每个字符,碰到第一个不同的就返回之前找到的前缀. 代码: class Solution { public ...
- 结合Vim ghostscript 将源代码文件转换成语法高亮的pdf格式文档
step 1: 安装ghostscript (debian 环境, 其他环境自行google) sudo apt-get install ghostscript step 2: 用Vim生成ps文件 ...
- HDU 1536 sg-NIM博弈类
题意:每次可以选择n种操作,玩m次,问谁必胜.c堆,每堆数量告诉. 题意:sg—NIM系列博弈模板题 把每堆看成一个点,求该点的sg值,异或每堆sg值. 将多维转化成一维,性质与原始NIM博弈一样. ...
- C#调用dll(C++(Win32))时的类型转换总结(转)
http://www.cnblogs.com/lidabo/archive/2012/06/05/2536737.html C++(Win 32) C# char** 作为输入参数转为char ...