luogu#P9161. Trees

Trees

Background

ZHY has many trees. Each tree has many nodes, and each node has a number on it, but he forgot what number was written on each node.

Problem Description

ZHY has mm trees. Every tree has the same shape and has nn nodes. Define (i,j)(i, j) as the jj-th node on the ii-th tree. You need to assign a value a(i,j)a_{(i,j)} to every node (i,j)(i, j), and it must satisfy the following conditions:

  • For all i[1,m],j[1,n]\forall i \in [1,m],\forall j \in [1,n], we have a(i,j){0,1}a_{(i,j)}\in\{0,1\}.

  • For all i[1,n]\forall i \in [1,n], we have j=1ma(j,i)1\sum_{j=1}^m a_{(j,i)}\le 1.

  • For any edge (u,v)(u,v) and i[1,m]i \in [1,m], we have a(i,u)+a(i,v)1a_{(i,u)}+a_{(i,v)}\le 1.

Please compute how many valid assignments there are, modulo 109+710^9+7. Note that these mm trees are ordered.

Input Format

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

The next n1n-1 lines each contain two positive integers u,vu, v, indicating that in each of the mm trees there is an undirected edge between uu and vv. It is guaranteed that the input forms a tree.

Output Format

Output one line containing the answer.

3 1
1 2
2 3
5
5 2
1 2
1 3
2 4
2 5
103

Hint

This problem uses bundled testdata.

For all testdata, 1n1061 \le n \le 10^6, 1m1091 \le m \le 10^9.

  • Subtask 0 (10 pts): n,m4n, m \le 4.
  • Subtask 1 (30 pts): n,m103n, m \le 10^3.
  • Subtask 2 (15 pts): n103n \le 10^3.
  • Subtask 3 (25 pts): m=1m = 1.
  • Subtask 4 (20 pts): No special constraints.

Translated by ChatGPT 5