#P16135. [ICPC 2018 NAIPC] Red Black Tree

[ICPC 2018 NAIPC] Red Black Tree

题目描述

You are given a rooted tree with nn nodes. The nodes are numbered 1n1\dots n. The root is node 1, and mm of the nodes are colored red, the rest are black.

You would like to choose a subset of nodes such that there is no node in your subset which is an ancestor of any other node in your subset. For example, if A is the parent of B and B is the parent of C, then you could have at most one of A, B or C in your subset. In addition, you would like exactly kk of your chosen nodes to be red.

If exactly mm of the nodes are red, then for all k=0mk = 0\dots m, figure out how many ways you can choose subsets with kk red nodes, and no node is an ancestor of any other node.

输入格式

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. Each test case will begin with a line with two integers nn (1n2×1051 \leq n \leq 2 \times 10^5) and mm (0mmin(103,n)0 \leq m \leq \min(10^3, n)), where nn is the number of nodes in the tree, and mm is the number of nodes which are red. The nodes are numbered 1..n1..n.

Each of the next n1n - 1 lines will contain a single integer pp (1pn1 \leq p \leq n), which is the number of the parent of this node. The nodes are listed in order, starting with node 2, then node 3, and so on. Node 1 is skipped, since it is the root. It is guaranteed that the nodes form a single tree, with a single root at node 1 and no cycles.

Each of the next mm lines will contain single integer rr (1rn1 \leq r \leq n). These are the numbers of the red nodes. No value of rr will be repeated.

输出格式

Output m+1m + 1 lines, corresponding to the number of subsets satisfying the given criteria with a number of red nodes equal to k=0mk = 0\dots m, in that order. Output this number modulo 109+710^9 + 7.

4 1
1
1
1
3
5
4
4 4
1
1
1
1
2
3
4
1
4
3
1
0
14 4
1
2
1
2
3
4
5
5
13
8
10
4
4
8
3
12
13
100
169
90
16
0