100 atcoder#ABC133E. [ABC133E] Virus Tree 2

[ABC133E] Virus Tree 2

Score : 500500 points

Problem Statement

You are given a tree with NN vertices and N1N-1 edges. The vertices are numbered 11 to NN, and the ii-th edge connects Vertex aia_i and bib_i.

You have coloring materials of KK colors. For each vertex in the tree, you will choose one of the KK colors to paint it, so that the following condition is satisfied:

  • If the distance between two different vertices xx and yy is less than or equal to two, xx and yy have different colors.

How many ways are there to paint the tree? Find the count modulo 1 000 000 0071\ 000\ 000\ 007.

What is tree?

A tree is a kind of graph. For detail, please see: Wikipedia "Tree (graph theory)"

What is distance?

The distance between two vertices xx and yy is the minimum number of edges one has to traverse to get from xx to yy.

Constraints

  • 1N,K1051 \leq N,K \leq 10^5
  • 1ai,biN1 \leq a_i,b_i \leq N
  • The given graph is a tree.

Input

Input is given from Standard Input in the following format:

NN KK

a1a_1 b1b_1

a2a_2 b2b_2

..

..

..

aN1a_{N-1} bN1b_{N-1}

Output

Print the number of ways to paint the tree, modulo 1 000 000 0071\ 000\ 000\ 007.

4 3
1 2
2 3
3 4
6

Figure

There are six ways to paint the tree.

5 4
1 2
1 3
1 4
4 5
48
16 22
12 1
3 1
4 16
7 12
6 2
2 15
5 16
14 16
10 11
3 10
3 13
8 6
16 8
9 12
4 3
271414432