题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures also conveniently numbered 1..N. Most conveniently of all, cow i is grazing in pasture i. Some pairs of pastures are connected by one of N-1 bidirectional…
本来想爆手速写个树剖,然而快下课了就手残写了了个n方的短小-- 暴力把查询的两个点中深的一个跳上来,加上边权,然后一起跳加边权就行了 #include<iostream> #include<cstdio> using namespace std; const int N=1005; int n,q,h[N],cnt,fa[N],va[N],de[N]; struct qwe { int ne,to,va; }e[N<<1]; int read() { int r=0,f…