#P10076. [GDKOI2024 普及组] 捉迷藏

[GDKOI2024 普及组] 捉迷藏

Problem Description

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

The game is played on a tree with nn nodes (numbered from 11 to nn).

At the start of the game, Zayin is at node aa, and Ziyin is at node bb. They take turns to move, with Zayin moving first. In each move, Zayin can move to any node whose distance from the current node is at most dada, and Ziyin can move to any node whose distance from the current node is at most dbdb (note that staying at the current node is allowed).

If after some move, one player catches the other, meaning they move onto the other player's node, then the game ends and the caught player loses.

If both Zayin and Ziyin play with optimal strategies, who will be the final winner?

Notes:

  • A tree with nn nodes means a connected undirected graph with nn nodes and n1n - 1 edges.
  • The distance between two nodes on the tree is defined as the number of edges on the shortest path connecting them.

Input Format

Each test point contains multiple test cases.

The first line contains two integers d,td, t, indicating the test point ID and the number of test cases. Each test case is described as follows.

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

The next n1n - 1 lines each contain two integers u,v(1u,vn,uv)u, v (1 \leq u, v \leq n, u \neq v), indicating that there is a directly connected edge between vertex uu and vertex vv. It is guaranteed that these edges form a tree.

The next qq lines each contain four integers a,b,da,db(1a,b,da,dbn)a, b, da, db(1 \leq a, b, da, db \leq n) describing one game, representing Zayin's starting node, Ziyin's starting node, Zayin's maximum moving distance, and Ziyin's maximum moving distance.

Output Format

For each game in each test case, output one line: Zayin or Ziyin, indicating the final winner. In particular, if the game still does not end within 1010510^{10^5} rounds, output Draw to indicate a draw.

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
Ziyin
Zayin
Zayin
Ziyin
Ziyin
Zayin
Zayin
Zayin
Draw
Ziyin

Hint

It is guaranteed that, over all test cases, the sum of nn does not exceed 10610^6, and the sum of qq does not exceed 10610^6.

Data Point ID n\sum n \leq Special Property
11 1010 None
22 100100 q=1q = 1
33 None
44 10410^4 q=1q = 1
55 None
66 10610^6 q=1q = 1
7,8,9,107,8,9,10 None

Translated by ChatGPT 5