Short paths - MarisaOJ: Marisa Online Judge

Short paths

Time limit: 1000 ms
Memory limit: 256 MB
Given a tree with $n$ vertices, each edge has a weight. Count the number of pairs of vertices $i < j$ such that the total weight on the shortest path between them does not exceed $k$. ### Input - The first line consists of two integers $n, k$. - The next $n - 1$ lines each contain three integers $u, v, w$, indicating an edge between vertex $u$ and $v$ with a weight of $w$. ### Output - Output an integer representing the answer. ### Constraints - $1 \leq n \leq 10^5$. - $1 \leq w, k \leq 10^9$. ### Sample test Input ``` 7 10 1 6 13 6 3 9 3 5 7 4 1 3 2 4 20 4 7 2 ``` Output: ``` 5 ```
Topic
Tree
Dynamic Programming
Rating 2000
Solution (0) Solution