CF1707D.Partial Virtual Trees

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kawashiro Nitori is a girl who loves competitive programming. One day she found a rooted tree consisting of nn vertices. The root is vertex 11. As an advanced problem setter, she quickly thought of a problem.

Kawashiro Nitori has a vertex set U=1,2,…,nU={1,2,\ldots,n}. She's going to play a game with the tree and the set. In each operation, she will choose a vertex set TT, where TT is a partial virtual tree of UU, and change UU into TT.

A vertex set S1S_1 is a partial virtual tree of a vertex set S2S_2, if S1S_1 is a subset of S2S_2, S1≠S2S_1 \neq S_2, and for all pairs of vertices ii and jj in S1S_1, LCA⁡(i,j)\operatorname{LCA}(i,j) is in S1S_1, where LCA⁡(x,y)\operatorname{LCA}(x,y) denotes the lowest common ancestor of vertices xx and yy on the tree. Note that a vertex set can have many different partial virtual trees.

Kawashiro Nitori wants to know for each possible kk, if she performs the operation exactly kk times, in how many ways she can make U=1U={1} in the end? Two ways are considered different if there exists an integer zz (1≤z≤k1 \le z \le k) such that after zz operations the sets UU are different.

Since the answer could be very large, you need to find it modulo pp. It's guaranteed that pp is a prime number.

川崎二鳥是一位熱愛競賽編程的女孩。某天,她發現了一棵包含 nn 個頂點的有根樹,其中根節點為頂點 11。作為一名資深的題目構造者,她迅速想到了一個問題。

川崎二鳥擁有一個頂點集合 U={1,2,…,n}U = \{1,2,\ldots,n\}。她將在這棵樹與該集合上進行一場遊戲。每次操作中,她會選擇一個頂點集合 TT,其中 TT 是 UU 的一個部分虛樹(partial virtual tree),並把 UU 更新為 TT。

若頂點集合 S1S_1 滿足以下條件,則稱其為頂點集合 S2S_2 的一個部分虛樹:

  • S1S_1 是 S2S_2 的子集;
  • S1≠S2S_1 \neq S_2;
  • 對於任意 i,j∈S1i,j \in S_1,其最近公共祖先 LCA⁡(i,j)\operatorname{LCA}(i,j) 也屬於 S1S_1。
    這裡 LCA⁡(x,y)\operatorname{LCA}(x,y) 表示樹上頂點 xx 和 yy 的最近公共祖先。注意:一個頂點集合可能具有多個不同的部分虛樹。

川崎二鳥想知道:對每一個可能的 kk,若她恰好執行 kk 次操作,最終使得 U={1}U = \{1\} 的方案數有多少?若存在某個整數 zz(1≤z≤k1 \le z \le k),使得經過 zz 次操作後所得的集合 UU 不同,則認為這兩種方案不同。

由於答案可能非常大,你需要輸出其對 pp 取模的結果。保證 pp 是一個質數。

输入格式

The first line contains two integers nn and pp (2≤n≤20002 \le n \le 2000, 108+7≤p≤109+910^8 + 7 \le p \le 10^9+9). It's guaranteed that pp is a prime number.

Each of the next n−1n-1 lines contains two integers uiu_i, viv_i (1≤ui,vi≤n1 \leq u_i, v_i \leq n), representing an edge between uiu_i and viv_i.

It is guaranteed that the given edges form a tree.

第一行包含两个整数 nn 和 pp(2≤n≤20002 \le n \le 2000,108+7≤p≤109+910^8 + 7 \le p \le 10^9+9)。保证 pp 是一个质数。

接下来的 n−1n-1 行每行包含两个整数 uiu_i、viv_i(1≤ui,vi≤n1 \leq u_i, v_i \leq n),表示 uiu_i 与 viv_i 之间的一条边。

保证所给的边构成一棵树。

输出格式

The only line contains n−1n-1 integers — the answer modulo pp for k=1,2,…,n−1k=1,2,\ldots,n-1.

唯一的一行包含 n−1n-1 个整数——即 k=1,2,…,n−1k=1,2,\ldots,n-1 时答案对 pp 取模的结果。

输入输出样例

  • 输入#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=1k=1, the only possible way is:

  1. 1,2,3,4→1{1,2,3,4} \to {1}.

When k=2k=2, there are 66 possible ways:

  1. 1,2,3,4→1,2→1{1,2,3,4} \to {1,2} \to {1};
  2. 1,2,3,4→1,2,3→1{1,2,3,4} \to {1,2,3} \to {1};
  3. 1,2,3,4→1,2,4→1{1,2,3,4} \to {1,2,4} \to {1};
  4. 1,2,3,4→1,3→1{1,2,3,4} \to {1,3} \to {1};
  5. 1,2,3,4→1,3,4→1{1,2,3,4} \to {1,3,4} \to {1};
  6. 1,2,3,4→1,4→1{1,2,3,4} \to {1,4} \to {1}.

When k=3k=3, there are 66 possible ways:

  1. 1,2,3,4→1,2,3→1,2→1{1,2,3,4} \to {1,2,3} \to {1,2} \to {1};
  2. 1,2,3,4→1,2,3→1,3→1{1,2,3,4} \to {1,2,3} \to {1,3} \to {1};
  3. 1,2,3,4→1,2,4→1,2→1{1,2,3,4} \to {1,2,4} \to {1,2} \to {1};
  4. 1,2,3,4→1,2,4→1,4→1{1,2,3,4} \to {1,2,4} \to {1,4} \to {1};
  5. 1,2,3,4→1,3,4→1,3→1{1,2,3,4} \to {1,3,4} \to {1,3} \to {1};
  6. 1,2,3,4→1,3,4→1,4→1{1,2,3,4} \to {1,3,4} \to {1,4} \to {1}.

在第一个测试用例中,当 k=1k=1 时,唯一可能的方式是:

  1. 1,2,3,4→1{1,2,3,4} \to {1}。

当 k=2k=2 时,共有 66 种可能的方式:

  1. 1,2,3,4→1,2→1{1,2,3,4} \to {1,2} \to {1};
  2. 1,2,3,4→1,2,3→1{1,2,3,4} \to {1,2,3} \to {1};
  3. 1,2,3,4→1,2,4→1{1,2,3,4} \to {1,2,4} \to {1};
  4. 1,2,3,4→1,3→1{1,2,3,4} \to {1,3} \to {1};
  5. 1,2,3,4→1,3,4→1{1,2,3,4} \to {1,3,4} \to {1};
  6. 1,2,3,4→1,4→1{1,2,3,4} \to {1,4} \to {1}。

当 k=3k=3 时,共有 66 种可能的方式:

  1. 1,2,3,4→1,2,3→1,2→1{1,2,3,4} \to {1,2,3} \to {1,2} \to {1};
  2. 1,2,3,4→1,2,3→1,3→1{1,2,3,4} \to {1,2,3} \to {1,3} \to {1};
  3. 1,2,3,4→1,2,4→1,2→1{1,2,3,4} \to {1,2,4} \to {1,2} \to {1};
  4. 1,2,3,4→1,2,4→1,4→1{1,2,3,4} \to {1,2,4} \to {1,4} \to {1};
  5. 1,2,3,4→1,3,4→1,3→1{1,2,3,4} \to {1,3,4} \to {1,3} \to {1};
  6. 1,2,3,4→1,3,4→1,4→1{1,2,3,4} \to {1,3,4} \to {1,4} \to {1}。

输入解题思路,AI测评打分。不知道怎么写?

首页