Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<vector<int>> g;
- vector<int> used;
- vector<int> up;
- vector<int> tin;
- vector<int> ans;
- int timer = 0;
- void dfs(int v, int parent) {
- tin[v] = up[v] = timer++;
- used[v] = 1;
- int cnt = 0;
- for (auto u : g[v]) {
- if (u == parent) {
- continue;
- }
- if (used[u]) {
- up[v] = min(up[v], tin[u]);
- } else {
- cnt += 1;
- dfs(u, v);
- up[v] = min(up[v], up[u]);
- if (up[u] >= tin[v] && parent != -1) {
- ans.push_back(v + 1);
- }
- }
- }
- if (parent == -1 && cnt > 1) {
- ans.push_back(v + 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment