1552 点的距离
我是来练习LCA的小菜鸡…
每次询问x和y之间的距离,问的这么直接,估计是个模板题
其实这个题非常的模板题,两个点的距离为两个点与LCA节点的深度之差
所以我们需要维护节点深度和最近公共祖先
然后套用公式就好了
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int SIZE=1e5+5;
int n,q;
int u,v;
int tot;
int depth[SIZE];
int f[SIZE];
int head[SIZE];
int st[SIZE][SIZE];//从j跳2^i到达的地方
struct node{
int next;
int to;
}e[SIZE];
void add(int u,int v)
{
tot++