Codeforces Round 372 (Div. 1)
E
Complete the Permutations
Codeforces
3400
原题
← D→
翻译中…

ZS the Coder is given two permutations $*p*$ and $*q*$ of ${1, 2, ..., *n*}$, but some of their elements are replaced with $0$. The distance between two permutations $*p*$ and $*q*$ is defined as the minimum number of moves required to turn $*p*$ into $*q*$. A move consists of swapping exactly $2$ elements of $*p*$.

翻译中…

ZS the Coder wants to determine the number of ways to replace the zeros with positive integers from the set ${1, 2, ..., *n*}$ such that $*p*$ and $*q*$ are permutations of ${1, 2, ..., *n*}$ and the distance between $*p*$ and $*q*$ is exactly $*k*$.

翻译中…

ZS the Coder wants to find the answer for all $0 ≤ *k* ≤ *n* - 1$. Can you help him?

翻译中…

Input

翻译中…

The first line of the input contains a single integer $*n*$ ($1 ≤ *n* ≤ 250$) — the number of elements in the permutations.

翻译中…

The second line contains $*n*$ integers, $*p*_{1}, *p*_{2}, ..., *p*_{*n*}$ ($0 ≤ *p*_{*i*} ≤ *n*$) — the permutation $*p*$. It is guaranteed that there is at least one way to replace zeros such that $*p*$ is a permutation of ${1, 2, ..., *n*}$.

翻译中…

The third line contains $*n*$ integers, $*q*_{1}, *q*_{2}, ..., *q*_{*n*}$ ($0 ≤ *q*_{*i*} ≤ *n*$) — the permutation $*q*$. It is guaranteed that there is at least one way to replace zeros such that $*q*$ is a permutation of ${1, 2, ..., *n*}$.

翻译中…

Output

翻译中…

Print $*n*$ integers, $*i*$-th of them should denote the answer for $*k* = *i* - 1$. Since the answer may be quite large, and ZS the Coder loves weird primes, print them modulo $998244353 = 2^{23}·7·17 + 1$, which is a prime.

翻译中…

Note

翻译中…

In the first sample case, there is the only way to replace zeros so that it takes $0$ swaps to convert $*p*$ into $*q*$, namely $*p* = (1, 2, 3), *q* = (1, 2, 3)$.

翻译中…

There are two ways to replace zeros so that it takes $1$ swap to turn $*p*$ into $*q*$. One of these ways is $*p* = (1, 2, 3), *q* = (3, 2, 1)$, then swapping $1$ and $3$ from $*p*$ transform it into $*q*$. The other way is $*p* = (1, 3, 2), *q* = (1, 2, 3)$. Swapping $2$ and $3$ works in this case.

翻译中…

Finally, there is one way to replace zeros so that it takes $2$ swaps to turn $*p*$ into $*q*$, namely $*p* = (1, 3, 2), *q* = (3, 2, 1)$. Then, we can transform $*p*$ into $*q*$ like following: image.

翻译中…

样例

Input #1
3
1 0 0
0 2 0
Output #1
1 2 1
InputCopy OutputCopy
Input #2
4
1 0 0 3
0 0 0 4
Output #2
0 2 6 4
InputCopy OutputCopy
Input #3
6
1 3 2 5 4 6
6 4 5 1 0 0
Output #3
0 0 0 0 1 1
InputCopy OutputCopy
Input #4
4
1 2 3 4
2 3 4 1
Output #4
0 0 0 1
InputCopy OutputCopy
题目信息
题号
715E
时间限制
5 s
内存限制
256 MB
标签
组合数学
FFT
图论
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。