统计在一个root下的两个子树,每个子树都和前面的运算一下再加进去对于这种需要排序的运算很麻烦,所以考虑先不去同子树内点对的算出合法点对个数,然后减去每一棵子树内的合法点对(它们实际上是不合法的,相当于一个容斥) 算点对用排序+双指针即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=1000005; int n,m,h[N],cnt,rt…
POJ1741 Tree + BZOJ1468 Tree Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an integer k,for every pair (u,v) of vertices is called valid i…