考虑每个点可以成为好节点的情况数,对于该节点,指定一个计数方向。
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
using ll=long long;
const int mod=1e9+7;
ll n,k,fac[(int)2e5+9],inv[(int)2e5+9],sz[(int)2e5+9],ans;
vector<int> g[(int)2e5+9];
int binom(int n,int m){
if(m>n||m<0)return 0;
return fac[n]*inv[n-m]%mod*inv[m]%mod;
}
int powmod(int a,int b){
int res=1;
for(;b>0;b>>=1,a=1ll*a*a%mod)if(b&1)res=1ll*res*a%mod;
return res;
}
void dfs(int u,int fa){
sz[u]=1;
for(auto it:g[u])if(it!=fa)dfs(it,u),sz[u]+=sz[it];
ans+=1ll*binom(sz[u],k/2)*binom(n-sz[u],k/2)%mod;
ans%=mod;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>k;
fac[0]=inv[0]=1;
for(int i=1;i<=n;++i)fac[i]=fac[i-1]*i%mod;
inv[n]=powmod(fac[n],mod-2);
for(int i=n-1;i;--i)inv[i]=inv[i+1]*(i+1ll)%mod;
for(int i=1,x,y;i<n;++i){
cin>>x>>y;
g[x].push_back(y),g[y].push_back(x);
}
if(k%2==0)dfs(1,0);
cout<<(ans*powmod(binom(n,k),mod-2)+1ll)%mod<<"\n";
return 0;
}