洛谷P2661 信息传递 最小环求解采用并查集求最小环. 只适用于本题的情况.对于新加可以使得两个子树合并的边,总有其中一点为其中一棵子树的根. 复杂度 \(O(n)\) . #include<bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 200005; int f[maxn], dist[maxn]; int n, to, ans; int father(int x) { if…