Hdu 4587 TWO NODES(割点)
来源:互联网 发布:佳都新太科技软件测试 编辑:程序博客网 时间:2024/05/12 14:52
题目链接
TWO NODES
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1178 Accepted Submission(s): 346
Problem Description
Suppose that G is an undirected graph, and the value ofstab 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 ofstab.
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 ofstab.
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.
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 ofstab.
Sample Input
4 50 11 22 33 00 2
Sample Output
2
Source
2013 ACM-ICPC南京赛区全国邀请赛——题目重现
题意:n点的无向图,问删除两个点以后,该图最多被分成多少个联通快?
题解:枚举删除的第一个点,对于剩下的图如果存在割点,那么删除的那个点一定是割点。同时在求割点的过程中,我们可以处理出删除这个割点可以把原来的联通快分成了几块。那么这个题就可以解决了。复杂度O(n^2)
详情见代码:
#include<cstdio>#include<iostream>#include<algorithm>#include<string.h>#define nn 5100using namespace std;typedef __int64 LL;int n,m;struct node{ int st,en,next;}E[nn*2];int p[nn],num;void init(){ memset(p,-1,sizeof(p)); num=0;}void add(int st,int en){ E[num].en=en; E[num].next=p[st]; p[st]=num++;}bool use[nn];int dfn[nn],low[nn],df;int dp[nn];void dfs(int id,int fa,int gen){ dfn[id]=low[id]=++df; dp[id]=1; int son=0; int i,w; for(i=p[id];i+1;i=E[i].next) { w=E[i].en; if(use[w]||w==fa) continue; if(dfn[w]==-1) { if(id==gen) son++; dfs(w,id,gen); low[id]=min(low[id],low[w]); if(low[w]>=dfn[id]&&id!=gen) { dp[id]++;//统计该割点可以把原来的联通快分成几块 } } else { low[id]=min(low[id],dfn[w]); } } if(id==gen) { dp[id]=son;//统计根节点可以把原来的联通快分成几块 }}int main(){ int i,j; int u,v; while(scanf("%d%d",&n,&m)!=EOF) { init(); memset(use,false,sizeof(use)); for(i=1;i<=m;i++) { scanf("%d%d",&u,&v); u++,v++; add(u,v); add(v,u); } int ans=0; for(i=1;i<=n;i++) { use[i]=true; memset(dfn,-1,sizeof(dfn)); df=0; int ix=0; for(j=1;j<=n;j++) { if(!use[j]&&dfn[j]==-1) { ix++; dfs(j,j,j); } } for(j=1;j<=n;j++) { if(use[j]) continue; ans=max(ans,ix-1+dp[j]); } use[i]=false; } printf("%d\n",ans); } return 0;}
0 0
- Hdu 4587 TWO NODES(割点)
- 【割点】 HDU 4587 TWO NODES
- HDU-4587 TWO NODES (割点[Tarjan])
- [HDU 4587] TWO NODES (Tarjan+割点)
- hdu 4587 TWO NODES (割点的应用)
- hdu 4587 TWO NODES (枚举+割点,5级)
- HDU 4587TWO NODES(割点,连通块,枚举)
- HDU 4587TWO NODES(割点,连通块,枚举)
- HDU 4587 TWO NODES 无向图的割点
- HDU 4587 TWO NODES(割点 模板题)
- HDOJ 4587 TWO NODES【割点】
- HDU 4587 —— TWO NODES(枚举+割顶)
- HDU-4587 TWO NODES(割点变形或者求点双连通分量)
- HDOJ 题目4587 TWO NODES(双联通,割点,枚举)
- hdu 4587 TWO NODES
- hdu 4587 TWO NODES
- HDU 4587 TWO NODES 删除两个点求连通分量
- hdu4587TWO NODES【割点】
- PAT 1001
- oracle SQL state [99999]; error code [17026]; 数字溢出
- 第十一周项目一:函数版星号图3
- java.lang.NullPointerException at org.apache.jsp.index_jsp._jspInit(index_jsp.java:22)
- 第十一周项目5当年第几天
- Hdu 4587 TWO NODES(割点)
- 优先级队列与堆排序
- Hibernate关联关系配置xml(一对多、一对一和多对多)
- 第十一周 项目六:输出1000以内的所有素数
- Linux中修改环境变量及生效方法
- htttpost模拟HTML中表单提交中的文件上传功能
- 微信企业号自带加密算法bug
- 【17173专访】Testin云测CEO王军:技术不是核心竞争力
- 第11周项目2.2求最大公约数(四个)