算法笔记--基环树

基环树:无向图,一个环,环上每个点都是树根

 

扣环:

int get_loop(int o, int u) {
    if(vis[u]) {
        st = u;
        return 1;
    }
    vis[u] = true;
    for (int i = 0; i < g[u].size(); i++) {
        if(g[u][i] != o) {
            int t = get_loop(u, g[u][i]);
            if(t) {
                if(t == 1) {
                    loop[cnt++] = u;
                    if(u != st) return 1;
                }
                return 2;
            }
        }
    }
    return 0;
}

基环内向树:有向图,在基环树的基础上每个节点的出度为1

基环外向树:有向图,在基环树的基础上每个节点的入度为1

 

猜你喜欢

转载自www.cnblogs.com/widsom/p/9492725.html