割点

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
52
53
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stack>
using namespace std;
#define R register
#define ll long long
#define fo(i,a,b) for(R int (i)=(a);(i)<=(b);++(i))
vector<int>a[10005];
int low[10005],pre[10005],n,m,ans=0;
bool iscut[10005];
int dfscnt=0;
void dfs(int x,int last)
{
low[x]=pre[x]=++dfscnt;
int child=0,siz=a[x].size()-1;
fo(i,0,siz)
{
int to=a[x][i];
if(!pre[to])
{
child++;dfs(to,x);
low[x]=min(low[x],low[to]);
if(low[to]>=pre[x])iscut[x]=1;
}
else if(pre[to]<pre[x]&&to!=last)low[x]=min(low[x],pre[to]);
}
if(last<0&&child==1)iscut[x]=0;
}
int main()
{
scanf("%d%d",&n,&m);
fo(i,1,m)
{
R int x,y;
scanf("%d%d",&x,&y);
a[x].push_back(y);
a[y].push_back(x);
}
fo(i,1,n)
{
if(!pre[i])dfs(i,-1);
if(iscut[i])ans++;
}
cout<<ans<<endl;
fo(i,1,n)if(iscut[i])printf("%d ",i);
return 0;
}
显示 Gitment 评论