Universal Cup Judging System

Universal Cup

Süre Sınırı: 2.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

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.