kruskal重构树套st表
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int st[200005][20],mx[200005][20],t;
int val[200005];
int fa[200005];
int n,m,q;
struct edge{
int u,v,w;
bool operator < (const edge &A) const{return w < A.w;}
}e[100005];
const bool cmp (const edge &a,const edge &b)
{
return a.w<b.w;
}
int get_f (int u)
{
if (fa[u]!=u) fa[u]=get_f(fa[u]);
return fa[u];
}
int qry (int ci,int cv)
{
for (int i=19;i>=0;i--)
if (st[ci][i] && cv>=mx[ci][i])
ci=st[ci][i];
return cv+val[ci];
}
void ins (int u,int v,int w)
{
if (u==v) return;
t++;
fa[u]=fa[v]=t;
val[t]=val[u]+val[v];
mx[u][0]=w-val[u];
mx[v][0]=w-val[v];
st[u][0]=st[v][0]=t;
}
void build_st()
{
for (int i=1;i<20;i++)
for (int j=1;j<t;j++)

最低0.47元/天 解锁文章
2402

被折叠的 条评论
为什么被折叠?



