洛谷 P3388 【模板】割点(割顶)
#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
using namespace std;
//Mystery_Sky
//
#define maxn 1000010
struct Edge{
int to, next;
}edge[maxn];
int vis[maxn], low[maxn], dfn[maxn], cut[maxn];
int head[maxn], cnt, tot;
inline void add_edge(int u, int v)
{
edge[++cnt].to = v;
edge[cnt].next = head[u];
head[u] = cnt;
}
void Tarjan(int u, int fa)
{
int child = 0;
low[u] = dfn[u] = ++tot;
vis[u] = 1;
for(int i = head[u]; i; i = edge[i].next) {
int v = edge[i].to;
if(!dfn[v]) {
Tarjan(v, fa);
low[u] = min(low[u], low[v]);
if(low[v] >= dfn[u] && u != fa) cut[u] = 1;
if(u == fa) child++;
}
low[u] = min(low[u], dfn[v]);
}
if(child >= 2 && u == fa) cut[u] = 1;
}
int ans, n, m;
int main() {
scanf("%d%d", &n, &m);
int u, v;
for(int i = 1; i <= m; i++) {
scanf("%d%d", &u, &v);
add_edge(u, v);
add_edge(v, u);
}
for(int i = 1; i <= n; i++) {
if(!dfn[i]) Tarjan(i, i);
if(cut[i]) ++ans;
}
printf("%d\n", ans);
for(int i = 1; i <= n; i++)
if(cut[i]) printf("%d ", i);
return 0;
}
唯愿,青春不辜负梦想,未来星辰闪耀