CF1610I.Mashtali vs AtCoder
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
After many unsuccessful tries, Mashtali decided to copy modify an AtCoder problem. 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,…,k are pinned and both players play optimally.
输入格式
The first line of input contains an integer n — the number of vertices ( 1≤n≤3⋅105 ).
The i -th of the following n−1 lines contains two integers ui,vi ( 1≤ui,vi≤n , ui=vi ) — 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.