| Insomnia 2025 |
|---|
| Finished |
In the mystical Land of Trees, there exists a rooted tree with $$$n$$$ nodes. The tree is rooted at node $$$1$$$. Each node is uniquely numbered from $$$1$$$ to $$$n$$$, and the tree structure is defined by $$$n-1$$$ edges. Additionally, each node $$$i$$$ has a value $$$a_i$$$.
Two nodes $$$u$$$ and $$$v$$$ are said to be compatible if they satisfy the following conditions:
You are given $$$q$$$ queries. In each query, you are given two nodes $$$u$$$ and $$$v$$$, and you must determine whether they are compatible.
The first line contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$ — the number of nodes in the tree.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \leq a_i \leq 10^5)$$$ — the values associated with each node.
The next $$$n-1$$$ lines describe the tree structure. Each of these lines contains two integers $$$x$$$ and $$$y$$$ $$$(1 \leq x, y \leq n)$$$, representing an edge between nodes $$$x$$$ and $$$y$$$.
The next line contains an integer $$$q$$$ $$$(1 \leq q \leq 10^5)$$$ — the number of queries.
The next $$$q$$$ lines each contain two integers $$$u$$$ and $$$v$$$ $$$(1 \leq u, v \leq n)$$$, representing a query where we must determine if nodes $$$u$$$ and $$$v$$$ are compatible.
For each query, output YES if the nodes $$$u$$$ and $$$v$$$ are compatible; otherwise, output NO. The output is case-insensitive.
5 1 1 2 1 2 1 2 2 3 3 4 4 5 4 4 5 3 5 2 5 1 4
NO YES NO NO
6 1 2 3 4 5 6 1 2 2 3 3 4 4 5 5 6 4 1 3 1 2 2 5 1 6
YES NO NO NO
| Name |
|---|


