Median Problem

TimeLimit:12000MS  MemoryLimit:262144KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description
We consider an integer $x$ as the $\textit{median}$ of a set $A$ containing $n$ distinct integers if it meets the following conditions:

- $x \in A$
- There are at least $\lfloor\frac{n+1}{2}\rfloor$ integers greater than or equal to $x$ in set $A$.
- There are at least $\lfloor\frac{n+1}{2}\rfloor$ integers less than or equal to $x$ in set $A$.

$\lfloor y \rfloor$ means the largest integer that does not exceed $y$. For example, if $A=\{1,3,4,5,7,9\}$, then either $4$ or $5$ is the median of set $A$.

Given a tree with $n$ nodes rooted at node $1$. Each node $u$ has an associated value $a_u$, where $a_1, a_2, \ldots, a_n$ is a permutation of $n$ (every integer from $1$ to $n$ occurs exactly once). Each node $u$ has another value $b_u$ satisfying the following condition:

- $b_u$ is the $\textit{median}$ of the set $\{ a_u \} \cup \{b_v \mid \text{node } u \text{ is the parent of node } v\}$. (The parent of node $v$ is the node directly connected to $v$ on the path to the root.)

Unfortunately, you forget some of $a_i$ and all $b_i$ except $b_1$. Now you are wondering how many different permutations $a_1,a_2,\dots,a_n$ that can match the $a_i$ and $b_1$ you remember when the tree satisfies the condition above. We consider two permutations $p_1,p_2,\dots,p_n$ and $q_1,q_2,\dots,q_n$ different if there exists an index $i$ satisfying $p_i \neq q_i$.

You are required to calculate the number of different permutations $a_1,a_2,\dots,a_n$ modulo $998244353$, for each $b_1 \in [1, n]$ respectively.
Input
The first line of the input contains an integer $T$ $(1 \leq T \leq 80)$, representing the number of test cases.

The first line of each test case contains an integer $n$ $(2 \leq n \leq 80)$, representing the number of nodes.

The second line of each test case contains $n - 1$ integers $p_2, p_3, \ldots, p_n \ (1 \leq p_i < i)$, where $p_i$ represents the parent of node $i$.

The third line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n \ (0 \leq a_i \leq n)$, representing the value of each node. $a_i = 0$ means you forget $a_i$. It is guaranteed that all non-zero $a_i$ are distinct.

It is guaranteed that there are at most $5$ test cases satisfying $n > 10$.
Output
For each test case, output a single line containing $n$ integers, the $k$-th of which is the answer when $b_1 = k$.

Don't print any extra spaces at the end of each line.
SampleInput
2
4
1 1 1
0 0 0 2
5
1 1 2 2
0 0 1 5 0
SampleOutput
0 6 6 0
0 2 4 0 0
Submit
题目统计信息详细
总AC数0
通过人数0
尝试人数0
总提交量0
AC率0.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: