标签:
★★ 输入文件:gd.in
输出文件:gd.out
简单对比
时间限制:1 s 内存限制:128 MB
输入文件名: gd.in
7
1 2
2 3
2 4
3 4
4 5
4 6
4 7
5 6
6 7
输出文件名:gd.out
2
2
4
割点
注意读入道路数量不等于n
1 /*by SilverN*/ 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 #include<vector> 8 using namespace std; 9 const int mxn=20000; 10 const int mxm=120; 11 vector<int>e[mxn]; 12 int gd[mxm]; 13 int n; 14 int root,dtime=0; 15 int dfn[mxm],low[mxm]; 16 int ans=0; 17 18 void add_edge(int u,int v){ 19 e[u].push_back(v); 20 e[v].push_back(u); 21 return; 22 } 23 void tarjan(int u){ 24 int i; 25 int tot=0; 26 low[u]=dfn[u]=++dtime; 27 int v; 28 for(i=0;i<e[u].size();i++){ 29 v=e[u][i]; 30 if(!dfn[v]){ 31 tarjan(v); 32 ++tot; 33 low[u]=min(low[v],low[u]); 34 if((u==root && tot>1)||(u!=root && low[v]>=dfn[u])) 35 if(!gd[u]) gd[u]=true,ans++; 36 } 37 else low[u]=min(low[u],dfn[v]); 38 } 39 return; 40 } 41 int main(){ 42 freopen("gd.in","r",stdin); 43 freopen("gd.out","w",stdout); 44 scanf("%d",&n); 45 int i,j; 46 int a,b; 47 while(scanf("%d%d",&a,&b)!=EOF) 48 add_edge(a,b); 49 for(i=1;i<=n;i++){ 50 if(!dfn[i]){ 51 root=i; 52 tarjan(i); 53 } 54 } 55 printf("%d\n",ans); 56 for(i=1;i<=n;i++){ 57 if(gd[i])printf("%d\n",i); 58 } 59 return 0; 60 }
标签:
原文地址:http://www.cnblogs.com/SilverNebula/p/5609049.html