A1390 | [COCI-2020-2021-contest5]#1 Magenta
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
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 1 to n, and n − 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 a, and Marin’s piece in node b. 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!
Although, who can say that a connected graph with n nodes, marked by integers from 1 to n, and n − 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 a, and Marin’s piece in node b. 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!
输入格式
The first line contains an integer n (2 ≤ n ≤ 100 000), the number of nodes.
The second line contains integers a and b (1 ≤ a, b ≤ n, a 6= b), initial nodes of Paula and Marin.
The next n − 1 lines describe the edges. Each line is of the form "x y color", where x and y (1 ≤ x, y ≤ n)
are the endpoints, and color is plava (Croatian for blue), crvena (Croatian for red) or magenta.
The second line contains integers a and b (1 ≤ a, b ≤ n, a 6= b), initial nodes of Paula and Marin.
The next n − 1 lines describe the edges. Each line is of the form "x y color", where x and y (1 ≤ x, y ≤ n)
are the endpoints, and color is plava (Croatian for blue), crvena (Croatian for red) or magenta.
输出格式
Output Paula if Paula will win, Marin if Marin will win, or Magenta if it’s a draw.
输入输出样例
输入 #1
3 1 3 3 2 magenta 2 1 magenta
输出 #1
Paula
输入 #2
5 3 5 1 2 magenta 1 3 magenta 2 4 plava 2 5 crvena
输出 #2
Marin
Subtask Points Constraints
1 30 2 ≤ n ≤ 100
2 30 All colors are magenta.
3 50 No additional constraints.
Clarification of the first example:
Paula will move to node 2, and then Marin can’t make a move.
Clarification of the second example:
Paula must move to node 1, and then Marin will move to node 2. Paula now can’t move to node 2, since
Marin is there, so she must return to node 3. Marin moves to node 1 and wins.
1 30 2 ≤ n ≤ 100
2 30 All colors are magenta.
3 50 No additional constraints.
Clarification of the first example:
Paula will move to node 2, and then Marin can’t make a move.
Clarification of the second example:
Paula must move to node 1, and then Marin will move to node 2. Paula now can’t move to node 2, since
Marin is there, so she must return to node 3. Marin moves to node 1 and wins.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted