A tree game

Consider this game for two players with a tree with n nodes: By turns,
the current player must choose a (non-empty) subtree and remove it. The
player that removes the root loses the game.

Assuming perfect play, can you tell if the player to play will win the
game? If so, can you find a winning move?

Input

Input consists of several cases, each with n, followed by the n − 1
edges x y of the tree, meaning that x is the parent of y. Assume
1 ≤ n ≤ 10⁵, and that the n − 1 given edges define a tree rooted at 1
with the nodes labelled from 1 to n.

Output

For every tree, print ‘L’ if the position is losing. Otherwise, print
the root of the subtree that should be removed. If there is more than
one winning move, choose the smallest one.

Problem information

Author: Ivan Geffner

Generation: 2026-01-25T11:09:15.611Z

© Jutge.org, 2006–2026.
https://jutge.org
