rt
#include<bits/stdc++.h>
using namespace std;
int n,m,head[20001],ver[100001],nxt[100001],dfn[20001],low[20001],tot=1,num,root,as;
bool cut[20001];
void add_edge(int x,int y){
++tot;
ver[tot]=y;
nxt[tot]=head[x];
head[x]=tot;
}
void tarjan(int p,int in_edge){
dfn[p]=low[p]=++num;
int flag=0;
for(int i=head[p];i;i=nxt[i]){
int to=ver[i];
if(!dfn[to]){
tarjan(to,i);
low[p]=max(low[p],low[to]);
if(low[to]>=dfn[p]){
++flag;
if(p!=root||flag>=2) cut[p]=true,++as;
}
}
else if(i!=(in_edge^1)) low[p]=min(low[p],dfn[to]);
}
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;++i){
int x,y;
cin>>x>>y;
add_edge(x,y);
add_edge(y,x);
}
for(int i=1;i<=n;++i){
if(!dfn[i]){
root=i;
num=0;
tarjan(i,0);
}
}
cout<<as<<'\n';
for(int i=1;i<=n;++i){
if(cut[i]) cout<<i<<' ';
}
return 0;
}
此程序样例输出为:
2
4 5