This is the easy version of the problem. The only difference is that in this version k≤min(n,3)�≤min(�,3). You can make hacks only if both versions of the problem are solved.
Chtholly and the floating islands.
LuoTianyi now lives in a world with n� floating islands. The floating islands are connected by n−1�−1 undirected air routes, and any two of them can reach each other by passing the routes. That means, the n� floating islands form a tree.
One day, LuoTianyi wants to meet her friends: Chtholly, Nephren, William, .... Totally, she wants to meet k� people. She doesn't know the exact positions of them, but she knows that they are in pairwise distinct islands. She define an island is good if and only if the sum of the distances†† from it to the islands with k� people is the minimal among all the n� islands.
Now, LuoTianyi wants to know that, if the k� people are randomly set in k� distinct of the n� islands, then what is the expect number of the good islands? You just need to tell her the expect number modulo 109+7109+7.
††The distance between two islands is the minimum number of air routes you need to take to get from one island to the other.
Input
The first line contains two integers n� and k� (1≤k≤min(n,3),1≤n≤2⋅1051≤�≤min(�,3),1≤�≤2⋅105) — the number of the islands and people respectively.
Next n−1�−1 lines describe the air routes. The i�-th of them contains two integers ui�� and vi�� (1≤ui,vi≤n,ui≠vi1≤��,��≤�,��≠��) — the islands connected by the i�-th air route.
Output
Print a single integer — the expect number of the good islands modulo 109+7109+7.
Formally, let M=109+7�=109+7. It can be shown that the answer can be expressed as an irreducible fraction pq��, where p� and q� are integers and q≢0�≢0 (modMmod�). Output the integer equal to p⋅q−1�⋅�−1 modMmod�. In other words, output such an integer x� that 0≤x<M0≤�<� and x⋅q≡p�⋅�≡� (modMmod�).
Code
/*******************************
| Author: chzu_w
| Problem: B1. LuoTianyi and the Floating Islands (Easy Version)
| Contest: Codeforces Round 872 (Div. 1)
| URL: https://codeforces.com/contest/1824/problem/B1
| When: 2023-05-08 20:05:13
|
| Memory: 256 MB
| Time: 2000 ms
*******************************/
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#include <stack>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define endl '\n'
#define pb push_back
#define NO cout << "NO" << endl;
#define YES cout << "YES" << endl;
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
typedef vector<int> VI;
typedef pair<int,int> PII;
ll MOD = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
mt19937 mrand(random_device{}());
const int N = 2e5 + 10;
VI e[N];
int siz[N];
void dfs(int u, int fa)
{
siz[u] = 1;
for (auto v: e[u])
{
if (v != fa)
{
dfs(v, u);
siz[u] += siz[v];
siz[u] %= MOD;
}
}
}
void solve()
{
int n, k; cin >> n >> k;
int d = 0;
rep (i, 1, n - 1) {
int u, v; cin >> u >> v;
e[u].pb(v);
e[v].pb(u);
d = u;
}
if (k == 1 || k == 3) {
cout << 1 << endl;
return;
}
ll ans = 0;
dfs(d, 0);
// rep (i, 1, n) cout << siz[i] << " \n"[i == n];
for (int i = 1; i <= n; ++i)
(ans += 1ll * siz[i] * abs(n - siz[i]) % MOD) %= MOD;
// cout << ans << endl;
int inv = n * (n - 1) % MOD * powmod(2, MOD - 2) % MOD;
inv = powmod(inv, MOD - 2);
cout << (ans * inv % MOD + 1) % MOD << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// int T;cin >> T;
// while ( T -- )
solve();
return 0;
}