https://www.luogu.org/problemnew/show/P3388
1 // luogu-judger-enable-o2 2 #include <iostream> 3 #include <cstdio> 4 #include <algorithm> 5 #include <cstring> 6 #include <cmath> 7 #include <set> 8 using namespace std; 9 struct Edge{int v, next;}G[200010]; 10 set<int>s; 11 int head[100010], tot, dfn[100010], low[100010], n, m; 12 bool cut[100010];int idx; 13 inline void add(int u, int v){ 14 G[++tot].v=v;G[tot].next=head[u];head[u]=tot; 15 G[++tot].v=u;G[tot].next=head[v];head[v]=tot; 16 } 17 inline void tarjan(int u, int fa){ 18 dfn[u] = low[u] = ++idx; 19 int child = 0; 20 for(int i=head[u];i;i=G[i].next){ 21 int v = G[i].v; 22 if (!dfn[v]){ 23 child++; 24 tarjan(v, u); 25 low[u] = min(low[u], low[v]); 26 if (u != fa && low[v] >= dfn[u]) s.insert(u); 27 if (fa == u && child == 2) s.insert(u); 28 } 29 else if (v != fa) low[u] = min(low[u], dfn[v]); 30 } 31 } 32 33 int main(void){ 34 scanf("%d%d", &n, &m); 35 while(m--){ 36 int u, v; scanf("%d%d", &u, &v);add(u, v); 37 } 38 for(int i = 1; i <= n; ++i) if (!dfn[i]) tarjan(i, i); 39 printf("%d\n", s.size()); 40 for(set<int>::iterator it = s.begin();it!=s.end(); ++it){ 41 printf("%d ", *it); 42 } 43 return 0; 44 }