問題一覧 > 通常問題

No.1075 Mountain on a Tree

レベル : / AI推定難易度 : 2200 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 29
作問者 : Kiri8128 / テスター : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 4352 / 自分の提出
問題文最終更新日: 2020-06-13 00:32:01
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 251 (順位表) の他の問題:

Problem Statement

Takahashi loves trees and mountains. There is a tree with $N$ vertices, numbered from $1$ to $N$. It has $N-1$ edges, and the $i$-th edge connects vertex $a_i$ and vertex $b_i$. A "mountain" on this tree is a way of writing an integer between $1$ and $K$, inclusive, on each vertex that satisfies the following condition.

  • There exists some $i\ (1\le i\le N)$ such that, for every $j\ (1\le j\le N,\ i\neq j)$, when traveling along the shortest path on the tree from vertex $i$ to vertex $j$, the sequence of integers written on the vertices passed through (including vertex $i$ and vertex $j$), arranged in order, is non-increasing. (*)

Output the number of mountains modulo $1000000007\ (=10^9+7)$.

Input

$N\ K$
$a_1\ b_1$
$\vdots$
$a_{N-1}\ b_{N-1}$

All inputs are integers.
$2\le N,\ K \le 1000$
$1\le a_i, b_i\le N\ (1\le i\le N-1)$
The given graph is guaranteed to be a tree.

Output

Output the number of mountains modulo $10^9+7$.

Sample

Sample 1
Input
3 2
1 2
2 3
Output
7

There are $8$ ways to write $1$ or $2$ on each vertex, and all of them satisfy the condition except the way that writes 2 - 1 - 2 on vertices 1, 2, 3 in order.

For example, writing 1 - 2 - 1 is a "mountain". This can be seen from the fact that the condition is satisfied by taking $i=2$ in (*). Note that writing 2 - 2 - 1 satisfies the condition with both $i=1$ and $i=2$ in (*), but it is counted only once.

Sample 2
Input
6 3
1 2
2 3
2 4
1 5
5 6
Output
188

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。