CF BUDDY
← Problems·

980E · The Number Games

2200 · data structures, greedy, trees

Problem: The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.

The nation has nn districts numbered from 11 to nn, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district ii is equal to 2i2^i.

This year, the president decided to reduce the costs. He wants to remove kk contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts.

The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.

Which contestants should the president remove?

Input Format: The first line of input contains two integers nn and kk (1k<n1061 \leq k < n \leq 10^6) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.

The next n1n-1 lines each contains two integers aa and bb (1a,bn1 \leq a, b \leq n, aba \ne b), that describe a road that connects two different districts aa and bb in the nation. It is guaranteed that there is exactly one path between every two districts.

Output Format: Print kk space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number.

Note: In the first sample, the maximum possible total number of fans is 22+25+26=1002^2 + 2^5 + 2^6 = 100. We can achieve it by removing the contestants of the districts 1, 3, and 4.

Sample Cases

Case 1

Input

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

Output

1 3 4

Case 2

Input

8 4
2 6
2 7
7 8
1 2
3 1
2 4
7 5

Output

1 3 4 5

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback