cychester

tarjan找基环树的环

 1 void dfs(int x, int last) {
 2     dfn[x] = ++sz;
 3     for(int i = head[x]; i; i = e[i].nxt) {
 4         if(i == last ^ 1) continue;
 5         int nt = e[i].to;
 6         if(dfn[nt]) {
 7             if(dfn[nt] < dfn[x]) continue;
 8             cur.push_back(x); mk[x] = 1;
 9             for(; nt != x; nt = pre[nt]) cur.push_back(nt), mk[nt] = 1;
10         }
11         else pre[nt] = x, dfs(nt, i);
12     }
13 }

 

posted on 2018-08-30 13:51  cychester  阅读(713)  评论(2编辑  收藏  举报

导航