#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5;
int n, k;
vector<int>g[nmax + 1];
const int mod = 1e9 + 7;
void cit(int &x) {
x = 0;
char c = getchar();
while (!isdigit(c))
c = getchar();
while (isdigit(c))
x = x * 10 + c - '0', c = getchar();
}
int dfs(int node, int father) {
int sol = 1, nr;
if (node == 1)
nr = k;
else nr = k - 1;
for (auto i : g[node]) {
if (i == father)
continue;
sol = (1LL * sol * nr) % mod;
sol = (1LL * sol * dfs(i, node)) % mod;
nr--;
}
return sol;
}
int main() {
freopen("colorare3.in", "r", stdin);
freopen("colorare3.out", "w", stdout);
cit(n);
cit(k);
for (int i = 1; i < n; ++i) {
int x, y;
cit(x), cit(y);
g[x].push_back(y);
g[y].push_back(x);
}
printf("%d",dfs(1,0));
}