ChuVanKhanh's blog

By ChuVanKhanh, history, 17 months ago, In English

Giving an undirected weighted graph of n (n <= 1e5) vertices , n — 1 edges and an positive integer k (k <= 1e9). Count the number of pairs (i , j) that i < j and the weight of the path from i to j is not bigger than k.

Input the first line contain n and k the following n — 1 lines each contains three positive integer u , v , w (u , v <= n , w <= 1e9)

Output the number of pairs (i , j) that the weight of the path from i to j is not bigger than k.

Sample

INPUT
6 8
1 2 2 
2 3 4
2 5 1
4 5 3
5 6 5

OUTPUT
14
  • Vote: I like it
  • -2
  • Vote: I do not like it

| Write comment?
»
17 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Is the graph simple and connected?

»
17 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

.

»
17 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Why did you just repost this?