CF1824B1.LuoTianyi and the Floating Islands (Easy Version)

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the easy version of the problem. The only difference is that in this version k≤min⁡(n,3)k\le\min(n,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 nn floating islands. The floating islands are connected by n−1n-1 undirected air routes, and any two of them can reach each other by passing the routes. That means, the nn floating islands form a tree.

One day, LuoTianyi wants to meet her friends: Chtholly, Nephren, William, .... Totally, she wants to meet kk 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†^{\dagger} from it to the islands with kk people is the minimal among all the nn islands.

Now, LuoTianyi wants to know that, if the kk people are randomly set in kk distinct of the nn islands, then what is the expect number of the good islands? You just need to tell her the expect number modulo 109+710^9+7.

†^{\dagger}The distance between two islands is the minimum number of air routes you need to take to get from one island to the other.

这是该问题的简单版本。唯一的区别在于本版本中 k≤min⁡(n,3)k\le\min(n,3)。仅当两个版本的问题均被解决时,才允许进行 Hack。

Chtholly 与浮空岛屿。

洛天依如今生活在一个拥有 nn 座浮空岛屿的世界中。这些浮空岛屿通过 n−1n-1 条无向空中航线相互连接,且任意两座岛屿均可经由这些航线相互抵达。换言之,这 nn 座浮空岛屿构成一棵树。

某日,洛天依想要会见她的朋友们:Chtholly、Nephren、William……总计她希望会见 kk 个人。她并不清楚这些人的具体位置,但知道他们分别位于互不相同的岛屿上。她定义一座岛屿是“好”的,当且仅当该岛屿到这 kk 个人所在岛屿的距离之和在所有 nn 座岛屿中达到最小值†^{\dagger}。

现在,洛天依想知道:若将这 kk 个人随机安置在 nn 座岛屿中的 kk 个互不相同的位置上,则“好”岛屿的期望数量是多少?你只需告诉她该期望值对 109+710^9+7 取模的结果。

†^{\dagger} 两座岛屿之间的距离定义为从一座岛屿到达另一座岛屿所需经过的最少空中航线数目。

输入格式

The first line contains two integers nn and kk (1≤k≤min⁡(n,3),1≤n≤2⋅1051\le k \le \min(n,3), 1\le n \le 2\cdot 10^5) — the number of the islands and people respectively.

Next n−1n−1 lines describe the air routes. The ii-th of them contains two integers uiu_i and viv_i (1≤ui,vi≤n,ui≠vi1 \le u_i,v_i \le n, u_i \neq v_i) — the islands connected by the ii-th air route.

第一行包含两个整数 nn 和 kk(1≤k≤min⁡(n,3)1\le k \le \min(n,3),1≤n≤2⋅1051\le n \le 2\cdot 10^5)—— 分别表示岛屿的数量和人的数量。

接下来的 n−1n-1 行描述了航空路线。其中第 ii 行包含两个整数 uiu_i 和 viv_i(1≤ui,vi≤n1 \le u_i,v_i \le n,ui≠viu_i \neq v_i)—— 表示由第 ii 条航空路线连接的两座岛屿。

输出格式

Print a single integer — the expect number of the good islands modulo 109+710^9 + 7.

Formally, let M=109+7M = 10^9 + 7. It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≢0q \not \equiv 0 (mod⁡M\operatorname{mod} M). Output the integer equal to p⋅q−1p \cdot q^{-1} mod⁡M\operatorname{mod} M. In other words, output such an integer xx that 0≤x<M0 \le x \lt M and x⋅q≡px \cdot q \equiv p (mod⁡M\operatorname{mod} M).

输出一个整数——即“好岛屿”数量的期望值对 109+710^9 + 7 取模的结果。

形式化地,令 M=109+7M = 10^9 + 7。可以证明该答案可表示为既约分数 pq\frac{p}{q},其中 pp 和 qq 均为整数,且 q≢0(modM)q \not \equiv 0 \pmod{M}。请输出整数 p⋅q−1 mod Mp \cdot q^{-1} \bmod M。换言之,请输出满足 0≤x<M0 \le x < M 且 x⋅q≡p(modM)x \cdot q \equiv p \pmod{M} 的整数 xx。

输入输出样例

  • 输入#1

    4 2
    1 2
    2 3
    3 4

    输出#1

    666666674
  • 输入#2

    5 1
    1 2
    2 3
    3 4
    3 5

    输出#2

    1

说明/提示

In the first example the air routes form the following tree:

If the people are in the islands 11 and 22, then islands 11 and 22 will be good.

The sum of the distances from island 11 or 22 to all the people is 1+0=11+0=1, which is the minimal. While the sum of the distances from island 33 to all the people is 2+1=32+1=3, which is greater than 11.

Like this, when the people are in island 11 and 33, then islands 1,21,2 and 33 will be good.

When the people are in islands 11 and 44, then islands 1,2,31,2,3 and 44 will be good.

When the people are in islands 22 and 33, then islands 22 and 33 will be good.

When the people are in islands 22 and 44, then islands 2,32,3 and 44 will be good.

When the people are in islands 33 and 44, then islands 33 and 44 will be good.

So the expect of the number of the good islands is 166\frac{16}{6}, which equals to 666666674666666674 modulo 109+710^9+7.

In the second example the air routes form the following tree:

There is always the only good island, so the expected number is 11.

在第一个例子中,航空路线构成如下树形结构:

若人员位于岛屿 11 和 22,则岛屿 11 和 22 为“好岛屿”。

岛屿 11 或 22 到所有人员的距离之和为 1+0=11+0=1,该值最小;而岛屿 33 到所有人员的距离之和为 2+1=32+1=3,大于 11。

类似地,当人员位于岛屿 11 和 33 时,岛屿 11、22 和 33 均为好岛屿。

当人员位于岛屿 11 和 44 时,岛屿 11、22、33 和 44 均为好岛屿。

当人员位于岛屿 22 和 33 时,岛屿 22 和 33 为好岛屿。

当人员位于岛屿 22 和 44 时,岛屿 22、33 和 44 为好岛屿。

当人员位于岛屿 33 和 44 时,岛屿 33 和 44 为好岛屿。

因此,“好岛屿”数量的期望值为 166\frac{16}{6},其对 109+710^9+7 取模的结果为 666666674666666674。

在第二个例子中,航空路线构成如下树形结构:

始终仅存在唯一一个好岛屿,因此期望值为 11。

输入解题思路,AI测评打分。不知道怎么写?

首页