求无向图中的割边(桥)

 1 inline void tarjan(int x,int edge) {
 2     int v;
 3     dfn[x] = low[x] = ++tot;
 4     for(int i = head[x];i != -1; i = e[i].next) {
 5         v = e[i].to;
 6         if(!dfn[v]) {
 7             tarjan(v,i);
 8             low[x] = min(low[x],low[v]);
 9             if(low[v] > dfn[x])
10                 bridge[i] = bridge[i^1] = true;
11         }
12         else if(i != edge)
13                 low[x] = min(low[x],dfn[v]);
14     }
15 }

 

posted @ 2019-09-08 11:37  Mr^Simon  阅读(195)  评论(0编辑  收藏  举报