Gas stations
Time limit3.5sMemory limit1024 MB
Given a tree of N villages, find the fewest villages to mark so that every path of exactly k roads contains a marked village.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Tree
- Solved
- No attempts yet
Problem
The KOI country has villages, numbered through . There are roads, and each road directly connects two different villages. The roads are also numbered through , and road connects village and village . Any two villages in the KOI country are connected by exactly one path.
A path from village to village is a sequence of villages that satisfies both of the following:
- Each pair of adjacent villages in the sequence is connected by a road.
- No village appears more than once in the sequence.
The length of a path is the number of roads it uses, which is .
You want to build gas stations in some of the villages. By KOI law, the stations must satisfy this condition:
- Every path of length contains at least one village with a gas station.
Find the minimum number of gas stations that satisfies this condition.
Input
The first line contains and , separated by a space. Each of the next lines contains and , the two villages connected by road , separated by a space.
Output
Print the minimum number of gas stations on the first line.
Constraints
- , , ()
- Any two villages are connected by exactly one path.
- At least one path of length exists.
- All input values are integers.