問題一覧 > 通常問題

No.1227 I hate ThREE

レベル : / AI推定難易度 : 1900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 69
作問者 : tyawanmusi / テスター : 37zigen
お気に入りにしたユーザー ProblemId : 4455 / 自分の提出
問題文最終更新日: 2020-08-30 01:40:56
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 265 (順位表) の他の問題:

Original Inspiration

ThREE
It is an interesting problem.

Problem Statement

There is a tree with $N$ vertices. The vertices are numbered from $1$ to $N$, and the $i$-th edge connects vertex $a_i$ and vertex $b_i$.

Takahashi, who loves $3$, is looking for sequences $p_1,p_2,\dots,p_N(1 \le p_i \le C)$ consisting of integers from $1$ to $C$ that satisfy the following condition.

  • For every pair of adjacent vertices $(i,j)$, $|p_i-p_j|=3$

For Takahashi, find the number of sequences satisfying the condition, modulo $10^9+7$.

Constraints

  • $2 \le N \le 1000$
  • $1 \le a_i,b_i \le N$
  • $4 \le C \le 10^9$
  • The given graph is a tree

Input

$N\ C$
$a_1\ \ b_1$
$a_2\ \ b_2$
$\vdots$
$a_{N-1}\ \ b_{N-1}$

Line $1$ contains $N,C$ separated by a space.
Line $i+1(1\le i \le N-1)$ contains $a_i,b_i$ separated by a space.

Output

Print the number of sequences modulo $10^9+7$ on 1 line.
Print a newline at the end.

Sample

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

$(1,4,4,1,1)$ and $(4,1,1,4,4)$ satisfy the condition.

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

In addition to those in Sample 1, $(2,5,5,2,2)$ and $(5,2,2,5,5)$ also satisfy the condition.

Sample 3
Input
5 7
1 2
1 3
3 4
3 5
Output
16

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