Description
Give a tree with n vertices,each edge have 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 are called valid if and only if Dist (u,v) not exceed K.
Write a program that would count how many pairs which is valid for a given tree.
Input
The input contains several test cases. The first line of all test case contains-integers n, K. (n<=10000) The following n-1 lines each contains three int Egers u,v,l, which means there is an edge between node U and V of length L.
The last test was followed by the zeros.
Output
The For each test case output the answer to a single line.
Sample Input
5 41 2 31 3 11 4 23 5 10 0
Sample Output
8
The title means to give a tree with edge, to satisfy the logarithm of dist (u,v) <=k (u,v)
Solution, divide the method, the tree points divide the rule, may consider you and V respectively to cross the node, for Root, to find out all child nodes to its distance d[i], and then statistics d[i]+d[j]<=k logarithm, here can use the monotonous team processing, then we recursively processing Root's child, because this , we forget to be in the same sub-tree, so subtract.
In fact, these are not important, these algorithms on the Internet are said to be clear, but the details are not said, is the time of processing, all require a root,root is the center of the tree, with DP, otherwise it will time out
POJ 1741 Tree