#include<stdio.h> #include<vector> #include<algorithm> using namespace std; const int MAX_V = 10000; vector<int> adj[MAX_V + 1]; int cnt, ck[MAX_V + 1], v, e; bool cutv[MAX_V + 1]; void dfs(int h, bool rt) { ck[h] = ++cnt; int vcnt = 0, mini = v; for (auto t : adj[h]) { if (!ck[t]) { dfs(t, false); if (ck[t] == ck[h]) cutv[h] = true; vcnt++; } mini = min(mini, ck[t]); } ck[h] = mini; if (rt) cutv[h] = vcnt >= 2; } int main() { scanf("%d %d", &v, &e); for (int i = 0; i < e; i++) { int a, b; scanf("%d %d", &a, &b); adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= v; i++) if (!ck[i]) dfs(i, true); int res = 0; for (int i = 1; i <= v; i++) if (cutv[i]) res++; printf("%d\n", res); for (int i = 1; i <= v; i++) if (cutv[i])printf("%d ", i); return 0; }
11266번: 단절점
https://www.acmicpc.net/problem/11266
피드 구독하기:
댓글
(
Atom
)
댓글 없음 :
댓글 쓰기