Pagini recente » Cod sursa (job #653583) | Cod sursa (job #2322769) | Cod sursa (job #1066537) | Cod sursa (job #2336755) | Cod sursa (job #1740975)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("colorare3.in");
ofstream fout("colorare3.out");
const int NMAX = 1e5 + 5;
const int MOD = 1e9 + 7;
int n; int k; int ans = 1;
vector<int> g[NMAX];
void dfs(int node, int father) {
int root = (node == 1) ? 0 : 1;
int sons = 0;
for(int i = 0 ; i < g[node].size(); ++i)
if(g[node][i] != father) {
ans = (1ll * ans * (k - root - sons) ) % MOD;
sons++;
dfs(g[node][i], node);
}
}
int main() {
fin >> n >> k;
for(int i = 1; i < n; ++i) {
int x; int y; fin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for(int i = 1 ; i <= n ; ++i)
if(g[i].size() > k) {
fout << 0 << '\n';
exit(0);
}
dfs(1, 0);
fout << ans << '\n';
return 0;
}