Diameters <Mar Circuits>

0

0 votes
Tree, Dynamic Programming, Algorithms, Medium-Hard
Problem

You are given a weighted tree that contains N nodes and an integer K. You are required to remove some edges from the tree (the number of removed edges can also be zero). If you remove M1 edges from the tree, then you can retrieve M different trees from the original tree. You have to make sure that each diameter of the tree is less than or equal to K. Determine the minimum value of M.

Note: Diameter of a weighted tree is defined to be the maximum sum of weights on a path over all simple paths in the tree.    

Input format

  • First line: Two space-separated integers N and K
  • Next N1 lines: Three space-separated integers u, v, and w denoting an edge of the length w, between u and v. It is guaranteed that the given graph in the input is a tree.

Output format

Print a single integer denoting the minimum value of M on a line.

Constraints

2N500
1K500
1u,vN
1w500

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

We have to remove at least 3 edges from this tree, which will result in 4 trees. Note that there can be multiple ways to remove the minimum number of edges.

Editor Image

?