HDU 4587 TWO NODES 枚举+割点
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587
TWO NODES
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1448 Accepted Submission(s): 441

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.
Please note that the endpoints of edge is marked in the range of [0,N-1], and input cases ends with EOF.
0 1
1 2
2 3
3 0
0 2
题意
给你个图,问你去掉两个点之后能有最多多少连通块。
题解
先枚举其中一个点,然后在剩下的点中求割点,Tarjan的时候统计一下每个割点分割几个连通块,取个最大的割点,然后再dfs一次求连通块个数。
代码
#include<cstdio>
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#define MAX_N 5555
using namespace std; vector<int> G[MAX_N];
bool vis[MAX_N];
int dfn[MAX_N],low[MAX_N],ind=; int cut[MAX_N]; int node; void Tarjan(int u,int p){
int child=;
dfn[u]=low[u]=++ind;
vis[u]=;
for(int i=;i<G[u].size();i++){
int v=G[u][i];
if(v==p||v==node)continue;
if(!vis[v]){
Tarjan(v,u);
low[u]=min(low[v],low[u]);
child++;
if((p==-&&child>)||(p!=-&&low[v]>=dfn[u]))
cut[u]++;
}
else
low[u]=min(dfn[v],low[u]);
}
} int n,m; void init(){
for(int i=;i<=n;i++)G[i].clear();
ind=;
memset(vis,,sizeof(vis));
memset(cut,,sizeof(cut));
} bool used[MAX_N];
int cu;
void dfs(int u,int p){
if(u==p||used[u]||u==node||u==cu)return;
used[u]=;
for(int i=;i<G[u].size();i++)dfs(G[u][i],u);
} int main(){
while(scanf("%d%d",&n,&m)==){
int stab=;
init();
int u,v;
for(int i=;i<m;i++) {
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
for(int i=;i<n;i++){
node=i;
memset(vis,,sizeof(vis));
ind=;
memset(cut,,sizeof(cut));
for(int j=;j<n;j++)
if((!vis[j])&&j!=node)
Tarjan(j,-);
int maxC=;
for(int j=;j<n;j++)
if(j!=node&&cut[j]>=maxC){
cu=j;
maxC=cut[j];
}
int ans=;
memset(used,,sizeof(used));
for(int j=;j<n;j++)
if((!used[j])&&j!=node&&j!=cu){
dfs(j,-);
ans++;
}
stab=max(stab,ans);
}
printf("%d\n",stab);
} return ;
}
HDU 4587 TWO NODES 枚举+割点的更多相关文章
- 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 割点
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意: 删除两个点,使连通块的数目最大化 题解: 枚举删除第一个点,然后对删除了第一个点的图跑 ...
- HDU - 4587 TWO NODES (图的割点)
Suppose that G is an undirected graph, and the value of stab is defined as follows: Among the expres ...
- HDU 4587 TWO NODES(割两个点的最大连通分支数)
http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意: 给一图,求割去两个点后所能形成的最大连通分支数. 思路: 对于这种情况,第一个只能枚举,然后在删除 ...
- hdu 4587 推断孤立点+割点+ 删除点之后,剩下多少连通分量
做了非常久...... 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4587 先枚举删除的第一个点,第二个点就是找割点.没有割点当然也有答案 学到 ...
- hdu 4587(割点的应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 思路:题目的意思很简单,就是删除任意2个节点以及关联的边,求图的最大连通分量数.我们知道删除割点 ...
- HDU 4587 B - TWO NODES tarjan
B - TWO NODESTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。
题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...
- hdu 4587(枚举+割顶)
TWO NODES Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
随机推荐
- Python中的列表(1)
1.什么是列表? 列表是由一组按特定顺序排列的元素组成. 2.如何表示? 在Python中用方括号([ ])来表示列表.栗子如下: contries = ['China','England','Fra ...
- c语言之内存管理
在计算机系统,特别是嵌入式系统中,内存资源是非常有限的.尤其对于移动端开发者来说,硬件资源的限制使得其在程序设计中首要考虑的问题就是如何有效地管理内存资源.本文是作者在学习C语言内存管理的过程中做的一 ...
- Python学习笔记: 闭包
闭包的基本定义 在计算机科学中,闭包(英语:Closure),又称词法闭包(Lexical Closure)或函数闭包(function closures),是引用了自由变量的函数.这个被引用的自由变 ...
- navicat12.0.24破解方法,简单易操作,亲测可行
navicat12.0.24 32bit 链接:https://pan.baidu.com/s/1dakPje0AzwE86p6ZRHfnsQ 密码:f1ve 破解文件 链接:https://pan. ...
- HDU 5237 Base64 模拟
题意: 输入一个明文串,输出\(k\)次\(Base64\)加密以后得到的串. 分析: 好像没什么Trick,直接模拟就行了. 注意:长度为\(3k+1\)的串,后面会有两个\(=\).长度为\(3k ...
- POJ-3278 广度优先搜索入门
#include<stdio.h> #include<stdlib.h> struct node{ int x; int s; }s[]; int main(){ ]={}; ...
- sql server 学习分享
http://www.cnblogs.com/liu-chao-feng/p/6144872.html
- 九度oj 题目1397:查找数段
题目描述: 在BaiDu搜索引擎里,如何提高搜索效率是研发人员为之奋斗的目标.现在,JOBDU密码库里也有一段数字片段S(0<长度<=100,000),HQ想通过智能搜索得到包含关键字P( ...
- div固定在屏幕底部
项目中需要实现div一直显示在屏幕的底部,不管页面有多长或者多端都需要满足. 在网上找的用js实现的,移动时会闪动,效果不是特别好.也可能是没找到好的. 相比js,我更希望使用css实现 1 < ...
- Dango notes II: class-based views
A view is a callable which takes a request and returns a response. A view can be function (function- ...