#P16464. [UOI 2026] Game on a Tree
[UOI 2026] Game on a Tree
题目描述
You are given a tree with vertices. Each leaf (that is, a vertex of degree ) has a status: or . Initially, all leaves are inactive.
There are queries of two types:
- --- change the status of leaf to the opposite one (active inactive). It is guaranteed that is a leaf (a vertex of degree ).
- --- determine who wins the game described below, if the token is initially placed at vertex . It is guaranteed that is a leaf (a vertex of degree ).
there is a token initially placed at vertex . Two players take turns, with the first player moving first. On each move, a player moves the token to an unvisited adjacent vertex. The game ends when the token is at a vertex from which it cannot move anywhere (that is, all adjacent vertices have already been visited --- this is necessarily a leaf of the graph). The second player wins if the token ends its move at an vertex; otherwise, the first player wins.
Online mode
If the input parameter , then in each query the actual vertex number is replaced by an encrypted number.
Consider a query of one of the two types:
- --- an encrypted query to change the status of a leaf;
- --- an encrypted query for a game from some starting vertex.
Let be a counter, initially equal to . For each query, the number is decrypted into the actual vertex number by the formula
That is:
- in query , you need to change the status of leaf ;
- in query , the game starts at vertex .
After each query, the counter is updated:
- after query with decrypted leaf : ;
- after query with answer : .
If , then the queries are not encrypted. In that case, in query the number is the leaf whose status must be changed, and in query the number is the starting vertex of the game.
输入格式
The first line contains three integers , , and (, , ).
The next lines contain the edges of the tree: two integers and each (, ).
The next lines contain the queries: type and argument (). If , then is an encrypted value.
输出格式
For each query of the second type, output one number in a separate line: if the first player wins, or if the second player wins.
4 5 0
1 2
1 3
1 4
2 1
1 2
1 3
1 4
2 1
1
2
5 5 0
1 2
1 3
3 4
3 5
2 3
1 2
1 4
1 5
2 3
1
2
4 5 1
1 2
1 3
1 4
2 1
1 1
1 4
1 2
2 3
1
2
提示
In the first example, the tree is a star with vertex in the center and leaves . Initially all leaves are inactive: for query , the first player makes the only move to any leaf, and the token stops at an inactive leaf --- the first player wins, so the answer is . After three queries of type that activate all leaves, for the repeated query , no matter where the first player moves, the token ends at an active leaf --- the second player wins, so the answer is .
In the second example, the tree has a shape: vertex is connected to vertices , , and to vertex , which has leaf attached to it. Query means that the tree is rooted at vertex . Before activating any leaves, the first player can reach an inactive leaf from vertex in one move (for example, to ) --- answer . After activating leaves , , and , all three possible paths from end at an active leaf, so the first player cannot avoid losing --- answer .
The third example demonstrates the online mode () on the same tree as in the first example. The initial value is , so the first encrypted query is decoded as and gives answer , after which . The next encrypted query is decoded as (because ), activating leaf , and then . Similarly, is decoded as (activating leaf , ), and --- as (activating leaf , ). The last encrypted query is decoded as and returns .
Scoring
- ( points): , ;
- ( points): a leaf never changes its status from active to inactive, , ;
- ( points): a leaf never changes its status from active to inactive, the token is initially at vertex in every query, ;
- ( points): , there exists an integer such that , and the tree edges are of the form for all .
- ( points): only vertex has degree greater than , ;
- ( points): , ;
- ( points): , ;
- ( points): no additional constraints.