Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

Panda 有一棵有 $n$ 個節點嘅有根樹,其中節點 $1$ 係根節點。樹入面嘅每個節點 $i$ 都有兩個標籤:$a_i$ 同 $b_i$。呢啲值入面有一部分被指定為萬用字元,用 $0$ 表示。具體嚟講,對於兩個值 $x$ 同 $y$,如果 $x = y$,或者佢哋之中至少有一個係萬用字元 $0$,就視為佢哋相等。

對於一個節點 $i$,設 $T_i$ 表示以節點 $i$ 為根嘅子樹,佢由節點 $i$ 本身以及佢喺樹入面嘅所有後代組成。對於由 $1$ 到 $n$ 嘅每個節點 $i$,Panda 都會問你以下問題,你需要獨立回答每一個問題:

  • 你可以執行任意次數嘅交換操作(包括零次)。喺每次操作入面,你可以揀子樹 $T_i$ 內嘅任意兩個節點 $u$ 同 $v$,並交換 $a_u$ 同 $a_v$。請判斷係咪可以透過某個交換序列,令子樹 $T_i$ 內嘅所有節點 $k$ 都滿足 $a_k$ 同 $b_k$ 相等。

請注意,每個詢問都係獨立嘅。你所考慮嘅交換只針對嗰個特定詢問,唔會影響後續詢問入面樹嘅初始狀態。

輸入格式

第一行包含一個整數 $T$ ($1 \le T \le 2 \times 10^5$),代表測試數據嘅組數。

對於每組測試數據,第一行包含一個正整數 $n$ ($1 \le n \le 2 \times 10^5$),表示節點嘅數量。

第二行包含 $n$ 個整數,其中第 $i$ 個係 $a_i$ ($0 \le a_i \le n$)。如果 $a_i = 0$,則代表一個萬用字元。

第三行包含 $n$ 個整數,其中第 $i$ 個係 $b_i$ ($0 \le b_i \le n$)。如果 $b_i = 0$,則代表一個萬用字元。

接住落嚟嘅 $n - 1$ 行描述樹嘅結構。每行包含兩個整數 $u, v$ ($1 \le u, v \le n$, $u \neq v$),代表連接節點 $u$ 同節點 $v$ 嘅一條邊。題目保證呢 $n - 1$ 條邊構成一棵樹。

保證所有測試數據入面 $n$ 嘅總和唔超過 $2 \cdot 10^5$。

輸出格式

對於每組測試數據,你必須輸出一行,包含一個長度為 $n$ 嘅二進制字串 $s$。如果子樹 $T_i$ 存在合法嘅交換方案,字串嘅第 $i$ 個字元 $s_i$ 應為 $1$,否則為 $0$。

範例

輸入格式 1

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

輸出格式 1

111011
01111
100

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.