Problem J. Kingdom

时间限制 3000 ms   内存限制 256 MB

Tom and Jerry were sent to a kingdom for some intelligence purpose. They were ordered to draw a map of the kingdom.
It's known that the kingdom consists of $n$ cities, numbered from $1$ to $n$, along with $n-1$ bidirectional roads connecting them. The cities form a binary tree, whose root is the kingdom's capital. The nodes on the tree either have no child, or a single left child, or a single right child, or both.
To avoid being caught spying, the commander ordered Tom and Jerry not to directly draw the map, but to record some specific information separately, which combined can deduce what the kingdom looks like.
When on a tree node, Tom was ordered to:
1. Record the label of current node.
2. Go to left child node(if any).
3. Go to right child node(if any).
Jerry was ordered to:
1. Go to left child node(if any).
2. Record the label of current node.
3. Go to right child node(if any).
But things often go south in Tom and Jerry's lives. When returned homeland with their information, they found that some of the numbers they wrote down are spotted. In despair, they decide to calculate how many kinds of form can the kingdom be according to the remaining information. As the number is large, you are only required to print it mod $998244353$.
 

输入数据

The first line contains an integer $T(1\le T\le 10)$, the number of test cases. Then $T$ cases follow.
For each test case:
In the first line, a integer $n(1\le n\le 100)$, the number of cities in the kingdom.
In the second line, $n$ integers $a_1,a_2,a_3,...,a_n$ separated by space, Tom's sequence.
In the third line, $n$ integers $b_1,b_2,b_3,...,b_n$ separated by space, Jerry's sequence($0\le a_i,b_i\le n$).
The spotted numbers are indicated by $0$.
 

输出数据

For each test case, output one line containing one integer, the number of corresponding kingdom's form mod $998244353$.
 

样例输入

复制
1
3
1 0 0
0 0 1

样例输出

样例说明

 Here are the 4 possible forms. 

 
  
 
 

提交

请先 登录

© 2025 FAQs Contact About