#P4178. Tree
Tree
Description
Given a tree with nodes where each edge has a weight, find the number of pairs of nodes whose distance on the tree is less than or equal to .
Input Format
The first line contains an integer , the number of nodes.
Lines to each contain three integers , indicating there is an edge between and with weight .
Line contains an integer .
Output Format
Output a single integer on one line, the answer.
7
1 6 13
6 3 9
3 5 7
4 1 3
2 4 20
4 7 2
10
5
Hint
Constraints
For all test points, it is guaranteed that:
- .
- .
- .
- .
Translated by ChatGPT 5
京公网安备 11011102002149号