#P17440. 水滴
水滴
Problem Description
Jiu and JiuZhu are playing a game.
There is a tree rooted at , and there is one drop of water on the tree. Jiu and JiuZhu take turns to move, with Jiu going first. In each move, you may choose a node on the tree that has a water drop, choose some of its children (you cannot choose none), gently remove the drop from this node, split it into several drops, and then gently place them onto the chosen children. It is easy to see that leaves cannot be operated on. When a player cannot make a move, she loses.
They like this game very much, so they plan to play many rounds. In each round, they agree on and , then wipe all water off the tree, and place exactly one drop of water only on . Next they start the game. During the game, water drops may only appear at nodes whose distance to is . Here, the distance between two nodes is the number of edges on the simple path between them. For each round, Jiu wants to know whether she has a winning strategy.
Formally, given a rooted tree with root , define the set of children of node as . For each game round , the set of operable nodes is . Let be the set of nodes that currently have water drops. Initially, . Then, each move may choose a node such that , and choose a non-empty set such that , delete from and add all elements of into . The player who cannot move loses. Determine whether the first player has a winning strategy.
Input Format
The first line contains two positive integers , representing the size of the rooted tree and the number of game rounds.
The next lines each contain two positive integers , representing an edge of the rooted tree.
The next lines each contain two non-negative integers , representing and in one game round.
Output Format
Output lines. The -th line represents the result of the -th game round: if Jiu has a winning strategy, output TAK, otherwise output NIE.
8 4
1 2
1 3
2 4
3 5
3 8
5 6
5 7
1 4
1 2
5 2
5 1
NIE
TAK
TAK
TAK
Hint
For all data, , , . The test points are evenly distributed.
| Test Point ID | n | q | Special Property |
|---|---|---|---|
| The tree is guaranteed random. | |||
| The tree is guaranteed random. | |||
| The tree is guaranteed to have a special shape. | |||
The random tree is generated as follows: for each with , its parent is chosen uniformly at random among the integers in .
The special shape of the tree is as follows: with root , the parent of is , and the parent of is either or .
Note: the maximum input size is about MB, and the maximum output size is about MB, so please use fast input/output. The provided file includes fastio.cpp, which you may use.
Time limit: s. Memory limit: MB.
Translated by ChatGPT 5