#include <iostream>
#include <vector>
using namespace std;
const long long mod = 1000000007;
long long N, D, a, b, L, W, LC, WC, sL, sW, sLC, sWC;
vector<int> el[100000];
bool lose[100000];
bool volt[100000];
long long c[100000];
long long oW[100000];
long long oL[100000];
long long h[100000];
void be(int x){
volt[x] = true; lose[x] = true;
for(int i:el[x]){
if(!volt[i]){
be(i);
if(lose[i]) h[x]++;
}
}
if(h[x]!=0) lose[x] = false;
}
void ertek(int x){
if(lose[x]){
c[x] = oW[x] + 1;
} else {
if(h[x]==1){
c[x] = oL[x];
} else {
c[x] = 0;
}
}
}
void ker(int x){
volt[x] = true;
for(int i:el[x]){
if(!volt[i]){
ker(i);
if(lose[i]){
oL[x] += c[i];
} else {
oW[x] += c[i];
}
}
}
ertek(x);
}
void reroot(int x, int y){
if(lose[y]){
h[x]--; oL[x] -= c[y];
} else {
oW[x] -= c[y];
}
if(h[x]==0) lose[x] = true;
ertek(x);
if(lose[x]){
h[y]++; oL[y] += c[x];
} else {
oW[y] += c[x];
}
if(h[y]!=0) lose[y] = false;
ertek(y);
}
void lep(int x){
volt[x] = true;
if(lose[x]){
L++; LC = (LC+c[x])%mod;
} else {
W++; WC = (WC+c[x])%mod;
}
for(int i:el[x]){
if(!volt[i]){
reroot(x,i);
lep(i);
reroot(i,x);
}
}
}
void step(long long pl, long long plc, long long pw, long long pwc){
sL = ((((pl * N) % mod) * W) % mod + (pwc * L) % mod + ((((pl * N)%mod - plc + mod)%mod) * L)%mod) % mod;
sLC = (plc * WC + pwc * LC) % mod;
sW = ((((pw * N) % mod) * W) % mod + (plc * L) % mod + ((((pw * N)%mod - pwc + mod)%mod) * L)%mod) % mod;
sWC = (pwc * WC + plc * LC) % mod;
}
void step2(long long pl, long long plc, long long pw, long long pwc){
L = ((((pl * N) % mod) * pw) % mod + (pwc * pl) % mod + ((((pl * N)%mod - plc + mod)%mod) * pl)%mod) % mod;
LC = (plc * pwc + pwc * plc) % mod;
W = ((((pw * N) % mod) * pw) % mod + (plc * pl) % mod + ((((pw * N)%mod - pwc + mod)%mod) * pl)%mod) % mod;
WC = (pwc * pwc + plc * plc) % mod;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> N >> D;
for(int i=0; i<N-1; i++){
cin >> a >> b;
el[a-1].push_back(b-1);
el[b-1].push_back(a-1);
}
be(0);
for(int i=0; i<N; i++) volt[i] = false;
ker(0);
for(int i=0; i<N; i++) volt[i] = false;
lep(0);
if(lose[0]){
sL = 1; sLC = c[0];
} else {
sW = 1; sWC = c[0];
}
//cout << L << ' ' << LC << ' ' << W << ' ' << WC << endl;
while(D>0){
if(D%2==1) step(sL, sLC, sW, sWC);
step2(L,LC,W,WC); D /= 2;
}
cout << sW << '\n';
return 0;
}