CF1707D.Partial Virtual Trees
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Kawashiro Nitori is a girl who loves competitive programming. One day she found a rooted tree consisting of n vertices. The root is vertex 1 . As an advanced problem setter, she quickly thought of a problem.
Kawashiro Nitori has a vertex set U={1,2,…,n} . She's going to play a game with the tree and the set. In each operation, she will choose a vertex set T , where T is a partial virtual tree of U , and change U into T .
A vertex set S1 is a partial virtual tree of a vertex set S2 , if S1 is a subset of S2 , S1=S2 , and for all pairs of vertices i and j in S1 , LCA(i,j) is in S1 , where LCA(x,y) denotes the lowest common ancestor of vertices x and y on the tree. Note that a vertex set can have many different partial virtual trees.
Kawashiro Nitori wants to know for each possible k , if she performs the operation exactly k times, in how many ways she can make U={1} in the end? Two ways are considered different if there exists an integer z ( 1≤z≤k ) such that after z operations the sets U are different.
Since the answer could be very large, you need to find it modulo p . It's guaranteed that p is a prime number.
输入格式
The first line contains two integers n and p ( 2≤n≤2000 , 108+7≤p≤109+9 ). It's guaranteed that p is a prime number.
Each of the next n−1 lines contains two integers ui , vi ( 1≤ui,vi≤n ), representing an edge between ui and vi .
It is guaranteed that the given edges form a tree.
输出格式
The only line contains n−1 integers — the answer modulo p for k=1,2,…,n−1 .
输入输出样例
输入#1
4 998244353 1 2 2 3 1 4
输出#1
1 6 6
输入#2
7 100000007 1 2 1 3 2 4 2 5 3 6 3 7
输出#2
1 47 340 854 880 320
输入#3
8 1000000007 1 2 2 3 3 4 4 5 5 6 6 7 7 8
输出#3
1 126 1806 8400 16800 15120 5040
说明/提示
In the first test case, when k=1 , the only possible way is:
- {1,2,3,4}→{1} .
When k=2 , there are 6 possible ways:
- {1,2,3,4}→{1,2}→{1} ;
- {1,2,3,4}→{1,2,3}→{1} ;
- {1,2,3,4}→{1,2,4}→{1} ;
- {1,2,3,4}→{1,3}→{1} ;
- {1,2,3,4}→{1,3,4}→{1} ;
- {1,2,3,4}→{1,4}→{1} .
When k=3 , there are 6 possible ways:
- {1,2,3,4}→{1,2,3}→{1,2}→{1} ;
- {1,2,3,4}→{1,2,3}→{1,3}→{1} ;
- {1,2,3,4}→{1,2,4}→{1,2}→{1} ;
- {1,2,3,4}→{1,2,4}→{1,4}→{1} ;
- {1,2,3,4}→{1,3,4}→{1,3}→{1} ;
- {1,2,3,4}→{1,3,4}→{1,4}→{1} .