daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. #define task "points"
  7.  
  8. using namespace std;
  9.  
  10. vector < vector < int > > G;
  11. vector <int> t, up;
  12. vector <bool> U;
  13. int time;
  14. vector <int> ans;
  15.  
  16. void dfs(int v, int p = -1) {
  17.     U[v] = true;
  18.     t[v] = up[v] = time++;
  19.     int children = 0;
  20.     for(size_t i = 0; i < G[v].size(); ++i) {
  21.         int to = G[v][i];
  22.         if(to == p)
  23.             continue;
  24.         if(!U[to]) {
  25.             dfs(to, v);
  26.             up[v] = min(up[v], up[to]);
  27.             if(up[to] >= t[v] && p != -1)
  28.                 ans.push_back(v + 1);
  29.             ++children;
  30.         }
  31.         else
  32.             up[v] = min(up[v], t[to]);
  33.     }
  34.     if(p == -1 && children > 1)
  35.         ans.push_back(v + 1);
  36. }
  37.  
  38. int main() {
  39.     freopen(task".in", "r", stdin);
  40.     freopen(task".out", "w", stdout);
  41.  
  42.     int n, m, a, b;
  43.     cin >> n >> m;
  44.     G.resize(n);
  45.     U.resize(n, false);
  46.     t.resize(n, 0);
  47.     up.resize(n, 0);
  48.     for(int i = 0; i < m; ++i) {
  49.         cin >> a >> b;
  50.         G[a-1].push_back(b-1);
  51.         G[b-1].push_back(a-1);
  52.     }
  53.  
  54.     time = 0;
  55.  
  56.     for(int i = 0; i < n; ++i)
  57.         if(!U[i])
  58.             dfs(i);
  59.      
  60.     sort(ans.begin(), ans.end());
  61.  
  62.     cout << ans.size() << endl;
  63.     for(size_t i = 0; i < ans.size(); ++i)
  64.         cout << ans[i] << endl;
  65.      
  66.  
  67.     return 0;
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top