F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Kingdom

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 170    Accepted Submission(s): 72


Problem Description
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$.
 

Input
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$.
 

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

Sample Input
1 3 1 0 0 0 0 1
 

Sample Output
4
 

Hint

Here are the 4 possible forms.

 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 16:42:48, Gzip enabled