anoosykh95

Untitled

Jul 22nd, 2016
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. // timer should be cleared with 0 each test
  2. // cc should be cleared by zero
  3. // clear the adjacency list
  4. //
  5. vector < int > v[MX];
  6. int low[MX] , timer[MX] , in[MX] , cc;
  7. stack < int > S;
  8. int T , Tn , comp , scc[MX];
  9. void dfs(int x){
  10.     low[x] = timer[x] = ++cc;
  11.     S.push(x); in[x] = 1;
  12.     for(int j=0;j<v[x].size();j++){
  13.         int nxt = v[x][j];
  14.         if(timer[nxt] == 0){
  15.             dfs(nxt);
  16.             low[x] = min(low[x] , low[nxt]);
  17.         }
  18.         else {
  19.             if(in[nxt])
  20.                 low[x] = min(low[x] , timer[nxt]);
  21.             }
  22.     }
  23.     if(low[x] == timer[x]){
  24.         ++comp;
  25.         while(1){
  26.             int node = S.top();
  27.             in[node] = 0; S.pop();
  28.             scc[node] = comp;
  29.             if(node == x) break;
  30.         }
  31.     }    
  32. }
Add Comment
Please, Sign In to add comment