You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int N = 200005, M = N << 1;
|
|
|
|
//链式前向星
|
|
int e[M], h[N], idx, w[M], ne[M];
|
|
void add(int a, int b, int c = 0) {
|
|
e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++;
|
|
}
|
|
|
|
int timestamp, root, cnt;
|
|
int low[N], dfn[N], cut[N];
|
|
|
|
void dfs(int u, int fa) {
|
|
low[u] = dfn[u] = ++timestamp;
|
|
int son = 0;
|
|
|
|
for (int i = h[u]; ~i; i = ne[i]) {
|
|
int j = e[i];
|
|
if (j == fa) continue;
|
|
if (!dfn[j]) {
|
|
son++;
|
|
dfs(j, u);
|
|
low[u] = min(low[u], low[j]);
|
|
if (u != root && low[j] >= dfn[u]) cut[u] = 1;
|
|
if (u == root && son >= 2) cut[u] = 1; // child指的是dfs中生成树中的孩子
|
|
}
|
|
low[u] = min(low[u], dfn[j]);
|
|
}
|
|
}
|
|
int n, m;
|
|
int main(void) {
|
|
//文件输入输出
|
|
#ifndef ONLINE_JUDGE
|
|
freopen("P3388.in", "r", stdin);
|
|
#endif
|
|
|
|
scanf("%d %d", &n, &m);
|
|
memset(h, -1, sizeof(h)); //链表的初始化
|
|
for (int i = 1; i <= m; i++) {
|
|
int a, b;
|
|
scanf("%d %d", &a, &b);
|
|
add(a, b), add(b, a);
|
|
}
|
|
for (root = 1; root <= n; root++)
|
|
if (!dfn[root])
|
|
dfs(root, root);
|
|
|
|
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;
|
|
} |