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个节点以及关联的边,求图的最大连通分量数.我们知道删除割点 ...
随机推荐
- 【Unity3D】自动寻路(Nav Mesh Agent组件)
1.首先添加场景模型 2.为场景模型(寻路路径)添加NavMesh渲染,操作:Windows->Navigation->勾选Navigation Static选项->不勾选Gener ...
- MVC ActionResult -- JavaScriptResult,JsonResult
以下是ActionResult的继承图: 大概的分类: EmptyResult:表示不执行任何操作的结果 ContentResult :返回文本结果 JavaScriptResult:返回结果为Jav ...
- ajax请求总是不成功?浏览器的同源策略和跨域问题详解
场景 码农小明要做一个展示业务数据的大屏给老板看,里面包含了来自自己网站的数据和来自隔壁老王的数据.那么自己网站的数据提供了 http://xiaoming.com/whoami 这样的数据接口隔壁老 ...
- Java Sleep() 与 Wait()的机制原理与区别
一.概念.原理.区别 Java中的多线程是一种抢占式的机制而不是分时机制.线程主要有以下几种状态:可运行,运行,阻塞,死亡.抢占式机制指的是有多个线程处于可运行状态,但是只有一个线程在运行. 回 ...
- Ui篇--layout_weight体验(实现按比例显示)
在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场景显得非常重要,比如我们需要按比例显示.android并没用提 ...
- 【LeetCode 201】Bitwise AND of Numbers Range
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- 跟我学机器视觉-HALCON学习例程中文详解-FUZZY检测用于开关引脚测量
跟我学机器视觉-HALCON学习例程中文详解-FUZZY检测用于开关引脚测量 * This example program demonstrates the basic usage of a fuzz ...
- [Hive - LanguageManual ] Explain (待)
EXPLAIN Syntax EXPLAIN Syntax Hive provides an EXPLAIN command that shows the execution plan for a q ...
- Hadoop-安装过程-单虚拟机版(伪分布式)(Ubuntu13.04版本下安装)
由于新装的Ubutu默认情况下,系统只安装了SSH客户端,需要自行安装SSH服务端 如何确定是否安装了SSH服务端? 可以通过命令ssh localhost,结果如下,即未安装SSH服务端: 安装 ...
- linux 切换c++版本
删除gcc-4.6的软连接文件/usr/bin/gcc.(只是删除软连接) 命令:sudo rm /usr/bin/gcc 然后建一个软连接,指向gcc-4.4. 命令:sudo ln -s /usr ...