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

建议使用的浏览器:

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

6986:Kanade Loves Maze Designing

题目描述
Kanade is designing a mini-game. It's a puzzle game that orders players to get out of a maze. Players should also collect as many kinds of elements as they can to gain a better score.

For the easy mode, the maze can be described as a tree. There are $n$ crossings and $n-1$ undirected passages which make the $n$ crossings connected. The $n$ crossings is numbered with integers from $1$ to $n$. Exactly one element is placed on each crossing. The kind of element placed at crossing $i$ is denoted by an integer $c_i$ in the range $[1,n]$.

To evaluate the maze's difficulty, Kanade wants to know how many kinds of elements appear on $p(u,v)$ for every two integers $u,v\in [1,n]$. $p(u,v)$ indicates the simple path from crossing $u$ to crossing $v$ in the maze.
输入解释
The first line of input contains one integer $T\ (1\le T\le 10)$, indicating the number of test cases.

For each test case, the first line contains one integer $n\ (2\le n\le 2000)$, indicating the number of crossings in the maze.

The second line contains $n-1$ integers $p_2,p_3,\ldots ,p_n\ (p_i<i)$, indicating that the $i$-th crossing is connected with the $p_i$-th crossing by a passage.

The third line contains $n$ integers $c_1,c_2,\ldots, c_n\ (1\le c_i\le n)$, indicating that the kind of element placed at crossing $i$ is $c_i$.

It is promised that for all test cases, $\sum n\le 5000$.
输出解释
For each test case, output $n$ lines. Each line contains two integers. Let $a_{i,j}$ be the number of kinds of elements appear on $p(i,j)$. Let
$$
f(i,x)=\sum_{j=1}^n a_{i,j}x^{j-1}
$$
Then for the $i$-th line, output $f(i,19560929)\bmod (10^9+7)$ and $f(i,19560929)\bmod (10^9+9)$, space separated.
输入样例
1
6
1 1 2 2 3
1 1 4 5 1 4
输出样例
495644981 518101442
495644981 518101442
397599492 896634980
612255048 326063507
495644981 518101442
397599492 896634980
来自杭电HDUOJ的附加信息
Hint Let A=(aij), then for the example, A equals to1 1 2 2 1 21 1 2 2 1 22 2 1 3 2 12 2 3 1 2 31 1 2 2 1 22 2 1 3 2 1

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

源链接: HDU-6986

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

共提交 0

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