Optical Communication Channels
Time limit1sMemory limit512 MB
Given a rooted tree where each node has at most k chosen edges, pick the maximum number of edges forming a degree-bounded subgraph, and among those the minimum total weight.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Flatland has cities numbered from 1 to . City 1 is the capital. Each city has one connection center, and centers can be linked to other centers by wired communication channels. Any two cities are joined by exactly one route through the channels, so the network is a tree. For a city with , let be the first city on the route from city to the capital.
The network is being upgraded, and some wired channels will be replaced with newer optical ones. An optical channel can only be installed in place of an existing wired channel. Replacing the channel that connects city with city costs . Because of technology limits, each connection center can be connected by optical channels to at most other centers.
The Flatland ministry wants a plan that makes the optical network as connected as possible, so it must upgrade as many channels as it can. Among plans with the same number of upgraded channels, the total cost should be minimal.
Help the ministry choose the channels to upgrade.
Input
The first line contains two integers and (, ). Each of the next lines contains two integers and (, ). The -th of these lines describes city .
Output
Print two integers and : the maximum number of channels that can be upgraded, and the minimum cost of upgrading that many channels.
Hint
In the first example, the network before and after the upgrade is shown in the figure below. Upgraded channels are drawn as thick lines. The maximum number of channels that can be upgraded is 4. The upgrade cost of every channel is 0, so costs are not shown.

There are other valid solutions that upgrade 4 channels.
In the second example, the network before and after the upgrade is shown below. Upgraded channels are thick lines, and the cost of each channel is written next to it. The maximum number of upgraded channels is 6, and the total cost of the optimal solution is 27.
