didedoshka

cut points

Dec 11th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. vector<vector<int>> g;
  2. vector<int> used;
  3. vector<int> up;
  4. vector<int> tin;
  5. vector<int> ans;
  6. int timer = 0;
  7.  
  8. void dfs(int v, int parent) {
  9.     tin[v] = up[v] = timer++;
  10.     used[v] = 1;
  11.     int cnt = 0;
  12.     for (auto u : g[v]) {
  13.         if (u == parent) {
  14.             continue;
  15.         }
  16.         if (used[u]) {
  17.             up[v] = min(up[v], tin[u]);
  18.         } else {
  19.             cnt += 1;
  20.             dfs(u, v);
  21.             up[v] = min(up[v], up[u]);
  22.             if (up[u] >= tin[v] && parent != -1) {
  23.                 ans.push_back(v + 1);
  24.             }
  25.         }
  26.     }
  27.     if (parent == -1 && cnt > 1) {
  28.         ans.push_back(v + 1);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment