#P9357. 「SiR-1」Lighthouse

    ID: 10056 远端评测题 3000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学递推洛谷原创O2优化树上距离组合数学洛谷月赛

「SiR-1」Lighthouse

Problem Description

Given a tree with nn nodes, each node has a weight wiw_i, initially 00. The initial score is s=0s=0.

Perform mm operations. In each operation, choose a node uu, add to ss the size of the connected component of nodes with the same weight that contains uu (that is, suppose we keep only the nodes whose weight equals wuw_u, and the edges connecting two nodes whose weights both equal wuw_u; then the contribution to the score is the size of the connected component containing uu at this time. Note that this does not actually delete any nodes or edges from the tree), and then increase wuw_u by 11.

For all nmn^m possible sequences of operations, compute the sum of their scores ss, modulo 109+710^9+7.

Input Format

The first line contains two positive integers, denoting n,mn,m.

The next n1n-1 lines each contain two positive integers, denoting the two endpoints u,vu,v of an edge.

Output Format

Output one integer, the result modulo 109+710^9+7.

3 2
1 3
2 3
40

Hint

For all data, it holds that 1n10001\leq n\leq 1000, 1m1051\leq m\leq 10^5, 1u,vn1\leq u,v\leq n, and the input is guaranteed to be a tree.

  • Subtask 0 (5 pts): n,m7n,m\le 7.
  • Subtask 1 (20 pts): n,m10n,m\le 10.
  • Subtask 2 (15 pts): n,m50n,m\le 50.
  • Subtask 3 (15 pts): n,m100n,m\le 100.
  • Subtask 4 (15 pts): n50n\le 50.
  • Subtask 5 (15 pts): the tree is a chain.
  • Subtask 6 (15 pts): no special restrictions.

This problem also enables subtask dependencies. Specifically:

  • For subtask i(i[1,3])i(i \in [1, 3]), it depends on subtasks 0(i1)0 \sim (i - 1).
  • For subtask 44, it depends on subtasks 020 \sim 2.
  • For subtask 66, it depends on subtasks 050 \sim 5.

Input Format

Output Format

Translated by ChatGPT 5