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 ...
随机推荐
- leetcode-10-basic
35. Search Insert Position Given a sorted array and a target value, return the index if the target i ...
- CodeForces - 948C Producing Snow(优先队列)
题意: n天. 每天你会堆一堆雪,体积为 v[i].每天都有一个温度 t[i] 所有之前堆过的雪在第 i 天体积都会减少 t[i] . 输出每天融化了的雪的体积. 这个题的正解我怎么想都很难理解,但是 ...
- UVa 1309 DLX Sudoku
16×16的数独. 看白书学的DLX,有些细节还有待消化,贴个模板先. #include <cstdio> #include <cstring> #include <al ...
- SPOJ 375 树链剖分 QTREE - Query on a tree
人生第一道树链剖分的题目,其实树链剖分并不是特别难. 思想就是把树剖成一些轻链和重链,轻链比较少可以直接修改,重链比较长,用线段树去维护. 貌似大家都是从这篇博客上学的. #include <c ...
- 《Scrum实战》第3次课【富有成效的每日站会】作业汇总
1组 崔儒: http://kecyru.blog.163.com/blog/static/2741661732017626101944123/ 2017-07-26 孟帅: http://www.c ...
- asp.net多线程在web页面中简单使用
需求:一个web页面 default.aspx 里面有两个控件GridView1,GridView2,通过两个线程分别加载绑定数据. 绑定GridView1:void BindCategory() ...
- jquery获得iframe内容的高度
html: <iframe name="rightgp" id="right_frame_h" src="/Poster/rightgp&quo ...
- python基础补漏-07-正则表达式
字符: . 匹配除了换行符以外的任意字符 \w 匹配字母或者数字或下划线或汉字(除了特殊字符外都能匹配) \s 匹配任意空白符 \d 匹配数字 \b 匹配单词的开始或者结束 ^ 匹配字符串 ...
- Leetcode 477.汉明距离总和
汉明距离总和 两个整数的 汉明距离 指的是这两个数字的二进制数对应位不同的数量. 计算一个数组中,任意两个数之间汉明距离的总和. 示例: 输入: 4, 14, 2 输出: 6 解释: 在二进制表示中, ...
- mybatis的嵌套查询(嵌套查询nested select和嵌套结果nested results查询)区别
(转自:http://blog.csdn.net/canot/article/details/51485955) Mybatis表现关联关系比hibernate简单,没有分那么细致one-to-man ...