#P7400. [COCI 2020/2021 #5] Magenta
[COCI 2020/2021 #5] Magenta
Description
Given a connected graph with nodes and edges, where the nodes are numbered . These edges are colored with different colors, including blue, red, and magenta.
Paula’s and Marin’s pieces start from nodes and , 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 , the number of nodes.
The second line contains integers , the starting positions of Paula’s and Marin’s pieces.
In the next lines, each line contains two integers and a string . If is , then the edge connecting is blue; if it is , then it is red; if it is , then it is magenta.
Output Format
If Paula wins, output .
If Marin wins, output .
If the game is a draw, output .
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 , and then Marin cannot move.
Sample 2 Explanation
Paula will go to node , and Marin will go to node . Paula can only go to node , and then Marin goes to node . At this point Paula cannot move, so Marin wins:

Constraints
This problem uses bundled testdata.
| Subtask | Points | Constraints and Notes |
|---|---|---|
| All edges in the connected graph are magenta | ||
| None |
For of the testdata, , , , .
Notes
The scoring for this problem follows the original COCI problem, with a full score of .
Translated from COCI2020-2021 CONTEST #5 T3 Magenta.
Translated by ChatGPT 5
京公网安备 11011102002149号