標籤:
TWO NODES
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1367 Accepted Submission(s): 410
Problem DescriptionSuppose 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.
InputThe 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.
OutputFor each graph in the input, you should output the value of
stab.
Sample Input
4 50 11 22 33 00 2
Sample Output
2
Source2013 ACM-ICPC南京賽區全國邀請賽——題目重現
Recommendzhuyuanchen520 | We have carefully selected several similar problems for you: 5231 5230 5229 5228 5227 題目大意:一個無向圖去掉兩個點後,最多產生幾個聯通分量思路:先去掉一個點,再對去掉點的圖進行tarjan求割點ac代碼
#include<stdio.h>#include<string.h>#define max(a,b) (a>b?a:b)#define min(a,b) (a>b?b:a)struct s{int u,v,next;}edge[10010];int head[5050],dfn[5050],low[5050],n,m,time,sum,ans,cnt,del,iscnt[5050];void init(){time=cnt=sum=ans=0;memset(head,-1,sizeof(head));//memset(vis,0,sizeof(vis));memset(iscnt,0,sizeof(iscnt));}void add(int u,int v){edge[cnt].u=u;edge[cnt].v=v;edge[cnt].next=head[u];head[u]=cnt++;}void tarjan(int u,int pre){low[u]=dfn[u]=time++;int i,j;for(i=head[u];i!=-1;i=edge[i].next){int v=edge[i].v;if(v==del)continue;if(dfn[v]==-1){tarjan(v,u);low[u]=min(low[v],low[u]);if(low[v]>=dfn[u])iscnt[u]++;}else{if(dfn[v]<dfn[u]&&v!=u){low[u]=min(low[u],dfn[v]);}}}if(pre<0)iscnt[u]--;}int main(){while(scanf("%d%d",&n,&m)!=EOF){int i,j;init();for(i=0;i<m;i++){int u,v;scanf("%d%d",&u,&v);add(u,v);add(v,u);}for(i=0;i<n;i++){del=i;time=0;memset(low,-1,sizeof(low));memset(dfn,-1,sizeof(dfn));memset(iscnt,0,sizeof(iscnt));sum=0;for(j=0;j<n;j++){if(j==del)continue;if(dfn[j]==-1){tarjan(j,-1);sum++;}}for(j=0;j<n;j++){if(j==del)continue;//printf("%d %d %d \n",sum,j,iscnt[j]);ans=max(ans,sum+iscnt[j]);}}printf("%d\n",ans);}}
HDOJ 題目4587 TWO NODES(雙聯通,割點,枚舉)