# include <bits/stdc++.h>
# define pp make_pair
using namespace std;
typedef long long LL;
const int maxn = 1e6+30;
const int N = 260000;
const LL mod = 1e9+7;
const int inf = 0x3f3f3f3f;
vector<int>g[N];
struct node{
int u, v, w;
}edge[maxn];
bool cmp(node i, node j){
return i.w > j.w;
}
int fa[N];
int Find(int x){
return x==fa[x]?x:fa[x]=Find(fa[x]);}
int f[N][23], h[N];
void dfs(int cur, int pre){
f[cur][0] = pre;
for(int i=1; i<=20; ++i){
f[cur][i] = f[f[cur][i-1]][i-1];
}
for(int i=0; i<g[cur].size(); ++i){
int to = g[cur][i];
if(to == pre) continue;
h[to] = h[cur] + 1;
dfs(to, cur);
}
}
int lca(int v, int u){
if(h[v] > h[u]) swap(v, u);
for(int i=0; i<=20; ++i)
if(h[u]-h[v]>>i & 1)
u=f[u][i];
最大生成树
最新推荐文章于 2021-04-03 11:15:56 发布