Pagini recente » Cod sursa (job #3191475) | Cod sursa (job #2894580) | Cod sursa (job #1961138) | Cod sursa (job #2046154) | Cod sursa (job #1992042)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin ("colorare3.in"); ofstream fout ("colorare3.out");
typedef long long i64;
const int nmax = 1e5;
const int mod = 1e9 + 7;
int k;
bool viz[nmax + 1];
vector< int > g[nmax + 1];
i64 ans;
int aux;
void dfs (int nod, int are_tata) {
viz[ nod ] = 1;
aux = (int)g[ nod ].size() - are_tata;
for (int i = k - are_tata - aux + 1; i <= k - are_tata; ++ i) {
ans = ans * i % mod;
}
for (const auto &i : g[ nod ]) {
if (viz[ i ] == 0) {
dfs(i, 1);
}
}
}
int main() {
int n;
fin >> n >> k;
for (int i = 1; i <= n - 1; ++ i) {
int x, y;
fin >> x >> y;
g[ x ].push_back( y );
g[ y ].push_back( x );
}
ans = 1;
dfs(1, 0);
fout << ans << "\n";
fin.close();
fout.close();
return 0;
}