AtCoder Beginner Contest 133
E
Virus Tree 2
AtCoder
⌀ 1505
原题
← DF →
翻译中…

Problem Statement

翻译中…

You are given a tree with $N$ vertices and $N-1$ edges. The vertices are numbered $1$ to $N$, and the $i$-th edge connects Vertex $a_i$ and $b_i$.

翻译中…

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

翻译中…
  • If the distance between two different vertices $x$ and $y$ is less than or equal to two, $x$ and $y$ have different colors.
翻译中…

How many ways are there to paint the tree? Find the count modulo $1\ 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 $x$ and $y$ is the minimum number of edges one has to traverse to get from $x$ to $y$.

翻译中…

Constraints

翻译中…
  • $1 \leq N,K \leq 10^5$
  • $1 \leq a_i,b_i \leq N$
  • The given graph is a tree.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N K
a_1 b_1
a_2 b_2
.
.
.
a_{N-1} b_{N-1}

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
4 3
1 2
2 3
3 4
Output #1
6
![Figure](https://img.atcoder.jp/ghi/491cd56a53e99ba7677ee4827b8f767a.png) There are six ways to paint the tree.
Input #2
5 4
1 2
1 3
1 4
4 5
Output #2
48
Input #3
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
Output #3
271414432
题目信息
题号
abc133_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。