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

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

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

The input will contain the description of several graphs. For each graph, the description consist of an integer N for the number of nodes, an integer M for the number of edges, and M pairs of integers for edges (3<=N,M<=5000). 
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的更多相关文章

  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(割两个点的最大连通分支数)

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

  3. HDU 4587 TWO NODES 割点

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意: 删除两个点,使连通块的数目最大化 题解: 枚举删除第一个点,然后对删除了第一个点的图跑 ...

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

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

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

  6. hdu 4738 Caocao's Bridges (tarjan求桥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题目大意:给一些点,用一些边把这些点相连,每一条边上有一个权值.现在要你破坏任意一个边(要付出相 ...

  7. HDU 3969 Hawk-and-Chicken(dfs+tarjan缩点优化,网上最详细解析!!!)

    Hawk-and-Chicken Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. HDU 4635 Strongly connected (Tarjan+一点数学分析)

    Strongly connected Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  9. hdu 4587(割点的应用)

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

随机推荐

  1. 【转】开始iOS 7中自动布局教程(一)

    原文网址:http://www.cocoachina.com/industry/20131203/7462.html 原文:Beginning Auto Layout Tutorial in iOS ...

  2. GreenDao官方文档翻译(上)

    笔记摘要: 上一篇博客简单介绍了SQLite和GreenDao的比较,后来说要详细介绍下GreenDao的使用,这里就贴出本人自己根据官网的文档进行翻译的文章,这里将所有的文档分成上下两部分翻译,只为 ...

  3. Linux下通过ioctl系统调用来获取和设置网络信息

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h&g ...

  4. [转] “error LNK2019: 无法解析的外部符号”之分析

    HiLoveS原文“error LNK2019: 无法解析的外部符号”之分析 最近在用VS 2008开发,初学遇到不少问题,最头疼的问题之一就是:LNK2019. 百度一下讲的并不够全面,反正都没解决 ...

  5. java web 学习十一(使用cookie进行会话管理)

    一.会话的概念 会话可简单理解为:用户开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话. 有状态会话:一个同学来过教室,下次再来教室,我们会知道这个同学曾 ...

  6. codeforces 691F Couple Cover 暴力

    分析:开一个300w的数组,统计,然后nlogn统计每个值在在序对第一个出现有多少种情况 时间复杂度:O(nlogn) n在3e6数量级 #include<cstdio> #include ...

  7. FOJ 1858 Super Girl 单调队列

    http://acm.fzu.edu.cn/problem.php?pid=1858 一个数组中  找两对元素,第一对元素和最大,第二对元素和最小,限制:一对元素中两个元素的距离在原数组中小于d.去掉 ...

  8. 【转】OFBiz安全组

    安全组标识 描述 用户系统级别BIZADMIN 全部商业应用程序权限组,具有全部商业应用程序管理权限,不是技术人员权限. bizadmin FLEXADMIN 缓存管理组,具有全部颗粒的权限. fle ...

  9. duilib List控件,横向滚动时列表项不移动或者移动错位的bug的修复

    转载请说明出处,谢谢~~ 这篇博客已经作废,只是留作记录,新的bug修复博客地址:http://blog.csdn.net/zhuhongshu/article/details/42264673 之前 ...

  10. wuzhicms内的全局函数--load_class()

    load_class() 可以加载并实例化/coreframe/app/模块名/libs/class/$class.class.php类文件里的对象,如果有扩展类文件EXT_$class.class. ...