#P51428. [COCI 2021.2] Magenta

[COCI 2021.2] Magenta

Description

Paula and Marin are playing a game on a tree. Not on a real tree, of course. That would be dangerous. Although, who can say that a connected graph with n nodes, marked by integers from 11 to nn, and n1n − 1 edges, is completely safe?

Before the game started, Paula colored some edges blue, and Marin colored some edges red. If some edge was colored by both, its final color is magenta. All edges were colored by at least one of them.

Paula’s piece starts the game in node aa, and Marin’s piece in node bb. Players alternate moves, and Paula goes first. When it’s their turn, the player must move their piece to some adjacent node which doesn’t also contain the opponents piece. Also, Paula can’t use red edges, and Marin can’t use blue edges, while both can use magenta edges. The player who can’t make a move loses.

Paula and Marin both play optimally. If they realize that the game can run forever, they will declare a draw. Determine the outcome of the game!

Input

The first line contains an integer nn (2n100 000)(2 \le n \le 100\ 000), the number of nodes.

The second line contains integers aa and bb (1a,bn,ab)(1 \le a, b \le n, a \not= b), initial nodes of Paula and Marin.

The next n1n − 1 lines describe the edges. Each line is of the form "x y colorx\ y\ color", where xx and yy (1x,yn)(1 \le x, y \le n) are the endpoints, and colorcolor is plava (Croatian for blueblue), crvena (Croatian for redred) or magenta.

Output

Output Paula if Paula will win, Marin if Marin will win, or Magenta if it’s a draw.

Example 1

3
1 3
3 2 magenta
2 1 magenta
Paula

Paula will move to node 22, and then Marin can’t make a move.

5
3 5
1 2 magenta
1 3 magenta
2 4 plava
2 5 crvena
Marin

Paula must move to node 11, and then Marin will move to node 22. Paula now can’t move to node 22, since Marin is there, so she must return to node 33. Marin moves to node 11 and wins.

T3P1.png

5
1 4
2 1 plava
1 3 crvena
5 2 plava
4 1 magenta
Magenta

Scoring

Subtask Constraints Points
11 2n1002\le n\le 100 30/11030/110
22 All colors are magenta.
33 No additional constraints. 50/11050/110