无根树转有根树

Posted -ackerman

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无根树转有根树相关的知识,希望对你有一定的参考价值。

std::vector<int> tree[maxn];
int fa[maxn];

void dfs(int u,int father) {
    int len = tree[u].size();
    for (int i = 0;i < len;i++) {
        int v = tree[u][i];
        if (v != father)
            dfs(v,fa[v] = u);
    }
}

以上是关于无根树转有根树的主要内容,如果未能解决你的问题,请参考以下文章