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.

54 lines
1.2 KiB

#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int 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 n, m, timestamp, tot;
int dfn[N], low[N], cut[N];
void tarjan(int u, int fa) {
dfn[u] = low[u] = ++timestamp;
int son = 0;
for (int i = h[u]; ~i; i = ne[i]) {
int j = e[i];
if (!dfn[j]) {
tarjan(j, fa);
low[u] = min(low[u], low[j]);
if (low[j] >= dfn[u] && u != fa) cut[u] = 1;
if (u == fa) son++;
}
low[u] = min(low[u], dfn[j]);
}
//根节点单独讨论
if (son >= 2 && u == fa) cut[u] = 1;
}
int main() {
memset(dfn, 0, sizeof(dfn));
memset(h, -1, sizeof(h));
scanf("%d%d", &n, &m);
while (m--) {
int a, b;
scanf("%d%d", &a, &b);
add(a, b), add(b, a);
}
for (int i = 1; i <= n; i++)
if (!dfn[i]) tarjan(i, i);
for (int i = 1; i <= n; i++)
if (cut[i]) tot++;
printf("%d\n", tot);
for (int i = 1; i <= n; i++)
if (cut[i]) printf("%d ", i);
return 0;
}