题目描述
Arun has a rooted tree of N vertices rooted at vertex 1. Each vertex can either be coloured black or white.
Initially, the vertices are coloured $A_{1}, A_{2}, \ldots A_{N}$, where $A_{i} \in$ {0, 1} denotes the colour of the i-th vertex (here 0 represents white and 1 represents black). He wants to perform some operations to change the colouring of the vertices to $B_{1}, B_{2}, \ldots B_{N}$ respectively.
Arun can perform the following operation any number of times. In one operation, he can choose any subtree and either paint all its vertices white or all its vertices black.
Help Arun find the minimum number of operations required to change the colouring of the vertices to $B_{1}, B_{2}, \ldots B_{N}$ respectively.
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N — the size of the tree.
- The second line of each test case contains $N space-separated integers A_{1}, A_{2}, \dots, A_{N}$ denoting the initial colouring of the vertices of the tree.
- The third line of each test case contains $N space-separated integers B_{1}, B_{2}, \dots, B_{N}$ denoting the final desired colouring of the vertices of the tree.
- The next N-1 lines contain two space-separated integers u and v — denoting an undirected edge between nodes u and v.
It is guaranteed that the edges given in the input form a tree.
------ Output Format ------
For each testcase, output the minimum number of operations required to obtain the desired colouring.
------ Constraints ------
$1 ≤ T ≤ 2 \cdot 10^{4}$
$1 ≤ N ≤ 3 \cdot 10^{5}$
$A_{i} \in \{0, 1\}$
$B_{i} \in \{0, 1\}$
$1 ≤ u, v ≤ N$ and $u \neq v$
- It is guaranteed that the edges given in the input form a tree.
- The sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$
----- Sample Input 1 ------
2
4
1 1 0 0
1 1 1 0
1 2
1 3
1 4
5
1 1 1 0 0
1 0 1 1 1
5 3
3 1
2 1
4 3
----- Sample Output 1 ------
1
2
----- explanation 1 ------
Test case $1$: Arun can choose the subtree rooted at $3$ and paint it black in one operation to achieve the desired colouring.
![sample1_{part1}]
$\rightarrow$
![sample1_{part2}]
Test case $2$: Consider the following sequence of operations.
![sample2_{part1}]
In the first operation, choose the subtree rooted at $3$ and paint it black.
![sample2_{part2}]
In the second operation, choose the subtree rooted at $2$ and paint it white.
![sample2_{part3}]
It can be shown that the desired colouring cannot be obtained in fewer operations.
输入格式
见题面
输出格式
见题面