#P10076. Zayin and Ziyin's Hide and Seek Game
Zayin and Ziyin's Hide and Seek Game
Zayin and Ziyin's Hide and Seek Game
Zayin and Ziyin are playing an exciting hide and seek game on a tree with n nodes (numbered from 1 to n). At the start of the game, Zayin is at node a while Ziyin is at node b. They take turns moving, with Zayin moving first. On each turn, Zayin can move to any node that is within a distance of at most \(d_a\) from his current node, and similarly, Ziyin can move to any node within a distance of at most \(d_b\). Note that a player may decide to remain on the same node.
If after any move one player lands on the node occupied by the other, the game immediately ends and the caught player loses. Assuming both players play optimally, determine who is the ultimate winner.
Notes:
- A tree with n nodes is an undirected connected graph with exactly n - 1 edges.
- The distance between two nodes on the tree is defined as the number of edges in the shortest path connecting them.
- The mathematical conditions for determining the winner are as follows:
If \(\text{dist}(a, b) \le d_a\), then Zayin catches Ziyin immediately. Otherwise, if \(d_b \le 2d_a\) or the diameter of the tree \(\le 2d_a\), then Zayin wins; otherwise, Ziyin wins.
inputFormat
The first line contains an integer t (\(1 \le t\le 10^4\)) denoting the number of test cases. The description of the test cases follows.
For each test case, the first line contains five integers \(n\), \(a\), \(b\), \(d_a\), and \(d_b\) where \(2 \le n \le 10^5\) and \(1 \le a, b \le n\), \(1 \le d_a, d_b \le n\). Then follow \(n - 1\) lines, each containing two integers \(u\) and \(v\) (\(1 \le u, v \le n\)) denoting an edge between nodes \(u\) and \(v\) in the tree.
It is guaranteed that the given edges form a tree. The sum of \(n\) over all test cases does not exceed \(10^5\).
outputFormat
For each test case, output a single line containing either Zayin
if Zayin is the winner when both play optimally, or Ziyin
otherwise.
sample
1
2 1 2 1 10
1 2
Zayin