当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7126:Median Problem

题目描述
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.
输入解释
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$.
输出解释
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.
输入样例
2
4
1 1 1
0 0 0 2
5
1 1 2 2
0 0 1 5 0
输出样例
0 6 6 0
0 2 4 0 0

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7126

最后修改于 2021-10-23T19:11:36+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
24000/12000MS(Java/Others) 262144/262144K(Java/Others)