Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // timer should be cleared with 0 each test
- // cc should be cleared by zero
- // clear the adjacency list
- //
- vector < int > v[MX];
- int low[MX] , timer[MX] , in[MX] , cc;
- stack < int > S;
- int T , Tn , comp , scc[MX];
- void dfs(int x){
- low[x] = timer[x] = ++cc;
- S.push(x); in[x] = 1;
- for(int j=0;j<v[x].size();j++){
- int nxt = v[x][j];
- if(timer[nxt] == 0){
- dfs(nxt);
- low[x] = min(low[x] , low[nxt]);
- }
- else {
- if(in[nxt])
- low[x] = min(low[x] , timer[nxt]);
- }
- }
- if(low[x] == timer[x]){
- ++comp;
- while(1){
- int node = S.top();
- in[node] = 0; S.pop();
- scc[node] = comp;
- if(node == x) break;
- }
- }
- }
Add Comment
Please, Sign In to add comment