博主考试的时候失智了 明明只差一句话就可以AC了的 然后抽风了交了暴力上去
标算是离线并查集 这里提供一种Kruskal重构树的简单做法
将重构树建出来后 此时是一个小根堆
我们倍增的往上跳 直到找到一个祖先的权值刚好小于K
显然 这个祖先的子树内的所有点到v的距离都是大于等于K的 因为此时u到v的距离是LCA(u,v),而显然,LCA(u,v)一定属于这个祖先的子树。
#include<bits/stdc++.h>
const int N=100005;
using namespace std;
template<class T>
inline void read(T &x)
{
x=0;
static char ch=getchar();
while(!isdigit(ch)) ch=getchar();
while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
}
int n,Q,cnt,first[2*N],tot,size[2*N];
struct Edge
{
int from,to,next,val;
bool operator <(const Edge &p) const
{
return this->val>p.val;
}
}e[N],edge[8*N];
inline void addedge(int x,int y)
{
tot++;
edge[tot].to=y; edge[tot].next=first[x]; first[x]=tot;
}
int father[2*N],up[2*N][22],val[2*N],depth[2*N];
inline int getfather(int x)
{
if(father[x]==x) return x;
return father[x]=getfather(father[x]);
}
void Kruskal_Rebuild()
{
sort(e+1,e+cnt+1);
for(registe