#P7400. [COCI 2020/2021 #5] Magenta

[COCI 2020/2021 #5] Magenta

Description

Given a connected graph with nn nodes and n1n-1 edges, where the nodes are numbered 1,2,,n1,2,\cdots,n. These n1n-1 edges are colored with different colors, including blue, red, and magenta.

Paula’s and Marin’s pieces start from nodes aa and bb, respectively. They move alternately, with Paula moving first. Paula’s piece can move only along blue or magenta edges, and Marin’s piece can move only along red or magenta edges. However, at any time, neither player may move onto the node where the other player’s piece is located. If one player cannot make a move, then the other player wins.

Assuming both Paula and Marin always play optimally, determine who will win in the end. If the game cannot be decided, then it is a draw.

Input Format

The first line contains an integer nn, the number of nodes.

The second line contains integers a,ba,b, the starting positions of Paula’s and Marin’s pieces.

In the next n1n-1 lines, each line contains two integers x,yx,y and a string color\text{color}. If color\text{color} is plava\texttt{plava}, then the edge connecting x,yx,y is blue; if it is crvena\texttt{crvena}, then it is red; if it is magenta\texttt{magenta}, then it is magenta.

Output Format

If Paula wins, output Paula\texttt{Paula}.

If Marin wins, output Marin\texttt{Marin}.

If the game is a draw, output Magenta\texttt{Magenta}.

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

Hint

Sample 1 Explanation

Paula’s optimal move is to go to node 22, and then Marin cannot move.

Sample 2 Explanation

Paula will go to node 11, and Marin will go to node 22. Paula can only go to node 33, and then Marin goes to node 11. At this point Paula cannot move, so Marin wins:

Constraints

This problem uses bundled testdata.

Subtask Points Constraints and Notes
11 3030 2n1002 \le n \le 100
22 All edges in the connected graph are magenta
33 5050 None

For 100%100\% of the testdata, 2n1052 \le n \le 10^5, 1a,bn1 \le a,b \le n, aba \neq b, 1x,yn1 \le x,y \le n.

Notes

The scoring for this problem follows the original COCI problem, with a full score of 110110.

Translated from COCI2020-2021 CONTEST #5 T3 Magenta.

Translated by ChatGPT 5