Advertisement
anoosykh95

Untitled

Jul 22nd, 2016
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. // depth should be cleared with 0 everytest
  2. // timer should be cleared
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. const int MX= (1<<20);
  6. vector < int > v[MX];
  7. int timer , low[MX] , depth[MX];
  8. vector < int > cutpoints;
  9. vector < pair < int , int > > bridges;
  10. void dfs(int x , int p){
  11.     int cc = 0 , is = 0;
  12.     depth[x] = low[x] = ++timer;
  13.     int l=v[x].size();
  14.     for(int j=0;j<l;j++){
  15.         int nxt=v[x][j];
  16.         if(nxt == p) continue;
  17.         if(depth[nxt] == 0) {
  18.             ++cc;
  19.             dfs(nxt , x);
  20.             low[x] = min(low[x] , low[nxt]);
  21.             if(low[nxt] > depth[x]) bridges.push_back({x , nxt});
  22.             if(low[nxt] >= depth[x] && p!=-1) is = 1;
  23.         }
  24.         else low[x] = min(low[x] , depth[nxt]);
  25.     }
  26.     if(p == -1 && cc>1) is = 1;
  27.     if(is) cutpoints.push_back(x);
  28. }
  29. int main(){
  30.     int n;
  31.     cutpoints.clear();
  32.     bridges.clear();
  33.     timer = 0;
  34.     for(int j=1;j<=n;j++){
  35.         v[j].clear();
  36.         depth[j] = 0;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement