Pagini recente » Cod sursa (job #2930043) | Cod sursa (job #341630) | Cod sursa (job #2676742) | Cod sursa (job #2768527) | Cod sursa (job #2547633)
#include <bits/stdc++.h>
#define input "colorare3.in"
#define output "colorare3.out"
#define MOD 1000000007
#define NMAX 100005
using namespace std;
typedef long long ll;
ifstream in(input);
ofstream out(output);
vector < int > muchii[NMAX];
queue < int > coada;
ll fact[NMAX], K;
bool uz[NMAX];
int N;
ll fasto_expo(ll base, ll exp)
{
if(!exp) return 1;
if(exp == 1) return base % MOD;
if(exp % 2) return base * fasto_expo((base * base) % MOD, exp / 2) % MOD;
return fasto_expo((base * base) % MOD, exp / 2) % MOD;
}
ll Arange_Calc(ll n, ll k)
{
ll A = fact[n];
ll B = fact[n - k];
B = fasto_expo(B, MOD - 2) % MOD;
return (A * B) % MOD;
}
void Read_Data()
{
in >> N >> K;
for(int i = 1; i < N; i++)
{
int x, y; in >> x >> y;
muchii[x].push_back(y);
muchii[y].push_back(x);
}
fact[0] = 1;
for(int i = 1; i <= N; i++)
fact[i] = (fact[i - 1] * i) % MOD;
}
void Solve()
{
ll R = 1;
coada.push(1);
uz[1] = 1;
while(!coada.empty())
{
int nod = coada.front(); coada.pop();
ll T = 0;
for(unsigned i = 0; i < muchii[nod].size(); i++)
{
int new_nod = muchii[nod][i];
if(!uz[new_nod])
{
T++; uz[new_nod] = 1; coada.push(new_nod);
}
}
//out << "Suntem in nodul " << nod << " si avem " << T << "\n";
ll P = 1;
if(nod == 1) P = Arange_Calc(K, T);
else P = Arange_Calc(K - 1, T);
R = (R * P) % MOD;
}
out << R << "\n";
}
int main()
{
Read_Data();
Solve();
return 0;
}