This page is still under construction.

Parts of this page are still being built. What you see may change.

Tree Cutting

Interview

Time limit1sMemory limit128 MB

Summary
On a tree of N nodes, print every node whose removal leaves each connected piece with at most floor(N/2) nodes, or NONE.
Level

Medium5 of 10

Topics
Tree, DFS, Recursion, Implementation
Solved
No attempts yet

Problem

Farmer John's NN barns are connected by a tree-shaped network. Bessie the cow wants to sabotage the network by cutting power to a single barn, which removes that barn together with all of its connections.

Removing one barn breaks the network into several pieces, each of which is still internally connected. To be as disruptive as possible, Bessie wants every resulting piece to contain no more than half of all the barns.

In other words, find every barn whose removal leaves each remaining piece with at most ⌊N/2⌋\lfloor N/2 \rfloor barns.

1≤N≤10 0001 \le N \le 10\,000

Input

The first line contains the number of barns NN. The barns are numbered from 11 to NN.

Each of the next N−1N-1 lines contains two integers XX and YY, indicating that barn XX and barn YY are connected.

Output

Print, in increasing numerical order and one per line, the number of every barn whose removal splits the network into pieces that each contain at most half of all the barns (⌊N/2⌋\lfloor N/2 \rfloor or fewer).

If no such barn exists, print a single line containing the word NONE.

Examples1

  1. Example 1

    Input
    10
    1 2
    2 3
    3 4
    4 5
    6 7
    7 8
    8 9
    9 10
    3 8
    
    Expected output
    3
    8