标签:
4 5 0 1 1 2 2 3 3 0 0 2
2
#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(双联通,割点,枚举)
标签:
原文地址:http://blog.csdn.net/yu_ch_sh/article/details/45873831