HDOJ 題目4587 TWO NODES(雙聯通,割點,枚舉)

來源:互聯網
上載者:User

標籤:

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(雙聯通,割點,枚舉)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.