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

建议使用的浏览器:

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

2974:Counting heaps

题目描述
We are given a rooted tree of n vertices. The vertices are to be labeled with numbers 1,2,..., n so that each label is unique and the heap condition holds, i.e. the label of any vertex is less than the label of its parent. How many such labellings exist? Since this number may be quite large, calculate only its
remainder modulo m.
输入解释
The input contains several tree descriptions. The first line contains the number of input trees t (t <=250).

Each tree description begins with a line containing the size of the tree n (1 <= n <= 500000) and an integer m (2 <= m <= 10^9). n - 1 lines follow, i-th of which contains p(i + 1), the number of the parent of the i + 1-th vertex (1 <= p(i + 1) <= i). Vertex number 1 will be the root in each tree, so its parent will not be given. Total size of the input will not exceed 50MB.
输出解释
For each tree output the number of its valid labellings modulo given m.
输入样例
4
3 1000000
1
1
4 1000000
1
1
1
5 1000000
1
2
3
4
5 1000000
1
1
3
3
输出样例
2
6
1
8


提示
来自杭电HDUOJ的附加信息
Recommend lcy

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

源链接: HDU-2974

最后修改于 2020-10-25T22:58:48+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 32768/32768K(Java/Others)