仙人掌找环板子

找出所有环中的点, 存在vector<int> v中

仙人掌要保证是双向边, 无重边自环且连通. 点仙人掌和边仙人掌都适用.

int n,cnt,dep[N],fa[N];
struct _ {int to,w;};
vector<_> g[N];
vector<int> v[N];

void get(int x, int y) {
    if (dep[x]<dep[y]) return;
    ++cnt;
    v[cnt].pb(y);
    for (; x!=y; x=fa[x]) v[cnt].pb(x);
}
void dfs(int x, int f) {
    fa[x]=f,dep[x]=dep[f]+1;
    for (_ e:g[x]) if (e.to!=f) {
		int y = e.to;
        if (dep[y]) get(x,y);
        else dfs(y,x);
    }   
}
原文地址:https://www.cnblogs.com/uid001/p/10752223.html