当且仅当点,存在一个子节点,点是割点
特别地,若为搜索树的根,只要它有两个或以上子节点,它就是割点
因为是小于等于,所以在求割点时,不必考虑父节点和重边问题1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using namespace std;
const int N=100050;
int n,m,low[N],dfn[N],num=0,cut[N],cnt=0;
vector<int> e[N];
inline int read()
{
register int x=0,t=1;
register char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') {t=-1;ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-48;ch=getchar();}
return x*t;
}
void tarjan(int o,int fa)
{
int son=0;
low[o]=dfn[o]=++num;
for(int i=0;i<e[o].size();i++)
{
int to=e[o][i];
if (!dfn[to])
{
tarjan(to,fa);
low[o]=min(low[o],low[to]);
if (low[to]>=dfn[o]&&o!=fa) cut[o]=1;
son++;
}
else low[o]=min(low[o],dfn[to]);
}
if (o==fa&&son>=2) cut[o]=1;
}
int main()
{
n=read(),m=read();
for(int i=1;i<=m;i++)
{
int u=read(),v=read();
e[u].push_back(v);
e[v].push_back(u);
}
for(int i=1;i<=n;i++)
if (!dfn[i]) tarjan(i,i);
for(int i=1;i<=n;i++)
if (cut[i]) cnt++;
printf("%d\n",cnt);
for(int i=1;i<=n;i++)
if (cut[i]) printf("%d ",i);
return 0;
}