QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 512 MB 總分: 100

#8161. Hide and Seek

统计

Zayin and Ziyin are playing an interesting game of hide-and-seek.

The game is played on a tree with $n$ nodes (numbered from $1$ to $n$).

At the beginning of the game, Zayin is at node $a$ and Ziyin is at node $b$. They take turns, with Zayin moving first. In each move, Zayin can move to any node at a distance of at most $da$ from their current position, and Ziyin can move to any node at a distance of at most $db$ from their current position (note that they can choose to stay at their current position).

If, after a move, one player catches the other (i.e., moves to the node where the other player is currently located), the game ends, and the caught player loses.

Assuming both Zayin and Ziyin play optimally, who will be the final winner?

Note: A tree with $n$ nodes is a connected undirected graph with $n$ nodes and $n-1$ edges. The distance between two nodes in a tree is defined as the number of edges on the shortest path connecting them.

Input

Each test case contains multiple test scenarios.

The first line contains two integers $d, t$, representing the test case ID and the number of scenarios. Each scenario is described as follows:

The first line contains two integers $n, q$ — the number of vertices and the number of queries, respectively.

The next $n-1$ lines each contain two integers $u, v$ ($1 \le u, v \le n, u \neq v$), representing a direct edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.

The next $q$ lines each contain four integers $a, b, da, db$ ($1 \le a, b, da, db \le n$) representing a game, where $a$ is Zayin's initial node, $b$ is Ziyin's initial node, $da$ is Zayin's maximum move distance, and $db$ is Ziyin's maximum move distance.

Output

For each game in each test scenario, output a single line containing "Zayin" or "Ziyin" to indicate the winner. Specifically, if the game does not end within $10^{10^5}$ turns, output "Draw" to indicate a tie.

Examples

Input 1

1 2
6 5
2 3
2 6
2 1
4 3
5 1
5 4 1 2
6 4 4 3
1 4 5 4
5 2 1 4
2 5 1 5
4 5
1 4
3 4
2 4
4 2 2 3
4 3 2 2
4 3 3 3
1 2 1 1
1 2 1 2

Output 1

Ziyin
Zayin
Zayin
Ziyin
Ziyin
Zayin
Zayin
Zayin
Draw
Ziyin

Constraints

It is guaranteed that the sum of $n$ over all test scenarios does not exceed $10^6$, and the sum of $q$ does not exceed $10^6$.

Test Case ID $\sum n \le$ Special Property
1 10 None
2 100 $q=1$
3 100 None
4 $10^4$ $q=1$
5 $10^4$ None
6 $10^6$ $q=1$
7, 8, 9, 10 $10^6$ None

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.