链接
题目描述
给出n个点的一棵树,多次询问两点之间的最短距离。
样例输入
3 2
1 2 10
3 1 15
1 2
3 2
样例输出
10
25
思路
就LCA模板呗
代码
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int to, next, val;
}g[40005];
int n, m, t;
int h[40005];
int fa[40005][16], dep[40005], dis[40005];
void add(int x, int y, int k)
{
g[++t] = (node){
y, h[x], k}; h[x] = t;