A14724 | Mashtali vs AtCoder
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
After many unsuccessful tries, Mashtali decided to copy modify [an AtCoder problem](https://atcoder.jp/contests/agc017/tasks/agc017_d). So here is his copied new problem:
There is a tree with $n$ vertices and some non-empty set of the vertices are pinned to the ground.
Two players play a game against each other on the tree. They alternately perform the following action:
- Remove an edge from the tree, then remove every connected component that has no pinned vertex.The player who cannot move loses(every edge has been deleted already).
You are given the tree, but not the set of the pinned vertices. Your task is to determine, for each $k$ , the winner of the game, if only the vertices $1, 2, 3, \ldots, k$ are pinned and both players play optimally.
There is a tree with $n$ vertices and some non-empty set of the vertices are pinned to the ground.
Two players play a game against each other on the tree. They alternately perform the following action:
- Remove an edge from the tree, then remove every connected component that has no pinned vertex.The player who cannot move loses(every edge has been deleted already).
You are given the tree, but not the set of the pinned vertices. Your task is to determine, for each $k$ , the winner of the game, if only the vertices $1, 2, 3, \ldots, k$ are pinned and both players play optimally.
输入格式
The first line of input contains an integer $n$ — the number of vertices ( $1 \le n \le 3 \cdot 10^5$ ).
The $i$ -th of the following $n-1$ lines contains two integers $u_i, v_i$ ( $1 \le u_i, v_i \le n$ , $u_i \ne v_i$ ) — the endpoints of the $i$ -th edge. It's guaranteed that these edges form a tree.
The $i$ -th of the following $n-1$ lines contains two integers $u_i, v_i$ ( $1 \le u_i, v_i \le n$ , $u_i \ne v_i$ ) — the endpoints of the $i$ -th edge. It's guaranteed that these edges form a tree.
输出格式
Print a string of length $n$ . The $i$ -th character should be '1' if the first player wins the $i$ -th scenario, and '2' otherwise.
输入输出样例
输入 #1
5 1 2 2 3 2 4 4 5
输出 #1
11122
输入 #2
5 1 2 2 3 1 4 4 5
输出 #2
21122
输入 #3
6 1 2 2 4 5 1 6 3 3 2
输出 #3
111111
输入 #4
7 1 2 3 7 4 6 2 3 2 4 1 5
输出 #4
2212222
Below you can see the tree in the first sample :
If $k = 1$ then the first player can cut the edge $(1, 2)$ .
If $k = 2$ or $k = 3$ , the first player can cut the edge $(2, 4)$ , after that only the edges $(1, 2)$ and $(2, 3)$ remain. After the second players move, there will be a single edge left for the first player to cut. So first player wins.
If $k = 1$ then the first player can cut the edge $(1, 2)$ .
If $k = 2$ or $k = 3$ , the first player can cut the edge $(2, 4)$ , after that only the edges $(1, 2)$ and $(2, 3)$ remain. After the second players move, there will be a single edge left for the first player to cut. So first player wins.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted