Diameters <Mar Circuits>
Practice
0 (0 votes)
Tree
Dynamic programming
Algorithms
Medium Hard
Problem
81% Success 269 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code
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 \(M-1\) 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 \(N-1\) 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
\(2 \leq N \leq 500\)
\(1 \leq K \leq 500\)
\(1 \leq u, v \leq N\)
\(1 \leq w \leq 500\)
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
TreeDynamic ProgrammingAlgorithmsMedium-Hard
Points:50
2 votes
Tags:
Medium-Hard
Points:50
2 votes
Tags:
GraphsDynamic ProgrammingAlgorithmsTrees
Editorial