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. 【转】VI/VIM常用命令

    原文网址:http://www.blogjava.net/woxingwosu/archive/2007/09/06/125193.html Vi是“Visual interface”的简称,它在Li ...

  2. SharePoint 2013让页面显示错误

    转:http://blog.csdn.net/zmoneyz/article/details/20460263 1. 在网站端口下,如80端口下的Web.config修改 (1)将<custom ...

  3. Entity Framework中编辑时错误ObjectStateManager 中已存在具有同一键的对象

    ObjectStateManager 中已存在具有同一键的对象.ObjectStateManager 无法跟踪具有相同键的多个对象. 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈 ...

  4. C# 使用C/S模式操作小票机打印

    此方式适用于市场上大多数的小票机 佳博.POS58 等,不适用于有些标签打印机 比如斑马打印机等 直接贴代码: private FileStream fs = null; [DllImport(&qu ...

  5. WPF应用加载图片URI指定需要注意的地方

    应用程序(.exe)加载图片: 可以省略"pack://application:,,," 打头,因为系统运行时需要的图片文件在Exe程序集(组合体)中:譬如: <Image ...

  6. jdbc:oracle:thin:@192.168.3.98:1521:orcl(详解)

    整理自互联网 一. jdbc:oracle:thin:@192.168.3.98:1521:orcljdbc:表示采用jdbc方式连接数据库oracle:表示连接的是oracle数据库thin:表示连 ...

  7. AutoLayout UITableViewCell 动态高度

    从这里http://www.cnblogs.com/liandwufan/p/4516956.html?utm_source=tuicool 转载过来的 -(UITableViewCell*)tabl ...

  8. 通过简单的Linux内核启动程序代码窥探操作系统的启动原理

    作者:吴乐  山东师范大学 <Linux内核分析> 孟宁 MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.程序设计与分析 ...

  9. Socket异步发送的同步控制

    在网络通信中,我们使用Socket异步发送数据,但在客户端,往往是需要等待服务器的返回结果后(握手过程)再往下执行,这就涉及到同步控制了,在多次的实现中,使用AutoResetEvent,实现不,即有 ...

  10. ASP.net MVC基础

    简单了解了下MVC的基本开发步骤后,又对MVC的语法和模版详细看看了,小小总结下 对mvc开发,首先是要对布局有个基本的认识.Razor引擎使页面元素更加清晰 简单认识下 可以加载css和js等文件, ...