#P8314. Optimal Park Placement

    ID: 21493 Type: Default 1000ms 256MiB

Optimal Park Placement

Optimal Park Placement

A city is composed of (n) communities connected by (n-1) roads such that there is a unique simple path between any two communities (i.e. the communities form a tree). The government plans to build (k) parks, with at most one park per community. The objective is to minimize the maximum distance from any community to its nearest park.

Given the layout of the communities and roads, determine which communities should have a park so that the maximum distance (in number of roads) from any community to the nearest park is minimized.

Note: If the selected number of communities (parks) is less than (k), you may choose additional communities arbitrarily.

inputFormat

The first line contains two integers \(n\) and \(k\) (1 \(\le n\le\) 105, 1 \(\le k\le n\)), representing the number of communities and the number of parks to build, respectively.

Each of the next \(n-1\) lines contains two integers \(u\) and \(v\) (1 \(\le u,v\le n\)) indicating that there is a road between community \(u\) and community \(v\>.

outputFormat

Output exactly \(k\) distinct integers (each between 1 and \(n\)) separated by spaces, representing the communities where parks are built. If there are multiple answers, any one is acceptable.

sample

5 2
1 2
2 3
2 4
4 5
4 2