Speed Cameras
Time limit1sMemory limit128 MB
Place the most cameras on the intersections of a tree so no simple route passes more than k cameras.
- Level
Medium7 of 10
- Topics
- Greedy, Tree, Dynamic programming
- Solved
- No attempts yet
Problem
The Lord Mayor of Bytetown wants to put radar speed cameras on the city's intersections. Bytetown has intersections numbered to and two-way street segments. Each segment joins two intersections, and the network is connected, so a driver can get from any intersection to any other one.
Cameras go on intersections, at most one per intersection, and the mayor wants as many of them as he can get. To keep the drivers' anger down, he also decided that a route which never passes through the same intersection twice may hold at most cameras. Cameras at the two ends of the route count towards that number.
Find the largest number of cameras that can be installed.
Input
The first line contains the number of intersections and the largest number of cameras allowed on a single route (, ).
Each of the next lines describes one street segment. Line holds two integers and (), meaning that a two-way street segment joins intersections and . For these lines are absent.
Output
Print one line with the largest number of cameras that can be installed in Bytetown.