CF1691F.K-Set Tree

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given a tree GG with nn vertices and an integer kk. The vertices of the tree are numbered from 11 to nn.

For a vertex rr and a subset SS of vertices of GG, such that ∣S∣=k|S| = k, we define f(r,S)f(r, S) as the size of the smallest rooted subtree containing all vertices in SS when the tree is rooted at rr. A set of vertices TT is called a rooted subtree, if all the vertices in TT are connected, and for each vertex in TT, all its descendants belong to TT.

You need to calculate the sum of f(r,S)f(r, S) over all possible distinct combinations of vertices rr and subsets SS, where ∣S∣=k|S| = k. Formally, compute the following: $$\sum_{r \in V} \sum_{S \subseteq V, |S| = k} f(r, S),$$ where VV is the set of vertices in GG.

Output the answer modulo 109+710^9 + 7.

给你一棵包含 nn 个顶点的树 GG 和一个整数 kk。树的顶点编号为 11 到 nn。

对于一个顶点 rr 和 GG 的一个顶点子集 SS(满足 ∣S∣=k|S| = k),我们定义 f(r,S)f(r, S) 为:当以 rr 为根时,包含 SS 中所有顶点的最小有根子树的大小。一个顶点集合 TT 被称为有根子树,当且仅当 TT 中的所有顶点连通,且对 TT 中的每个顶点,其所有后代也均属于 TT。

你需要计算所有可能的顶点 rr 与所有满足 ∣S∣=k|S| = k 的不同子集 SS 对应的 f(r,S)f(r, S) 之和。形式化地,计算下式:

∑r∈V∑S⊆V, ∣S∣=kf(r,S),\sum_{r \in V} \sum_{S \subseteq V,\, |S| = k} f(r, S),

其中 VV 是树 GG 的顶点集。

输出结果对 109+710^9 + 7 取模。

输入格式

The first line contains two integers nn and kk (3≤n≤2⋅1053 \le n \le 2 \cdot 10^5, 1≤k≤n1 \le k \le n).

Each of the following n−1n - 1 lines contains two integers xx and yy (1≤x,y≤n1 \le x, y \le n), denoting an edge between vertex xx and yy.

It is guaranteed that the given edges form a tree.

第一行包含两个整数 nn 和 kk(3≤n≤2⋅1053 \le n \le 2 \cdot 10^5,1≤k≤n1 \le k \le n)。

接下来的 n−1n - 1 行每行包含两个整数 xx 和 yy(1≤x,y≤n1 \le x, y \le n),表示顶点 xx 与顶点 yy 之间的一条边。

保证所给的边构成一棵树。

输出格式

Print the answer modulo 109+710^9 + 7.

对 109+710^9 + 7 取模后输出答案。

输入输出样例

  • 输入#1

    3 2
    1 2
    1 3

    输出#1

    25
  • 输入#2

    7 2
    1 2
    2 3
    2 4
    1 5
    4 6
    4 7

    输出#2

    849

说明/提示

The tree in the second example is given below:

We have 2121 subsets of size 22 in the given tree. Hence, $$S \in \left\{\{1, 2\}, \{1, 3\}, \{1, 4\}, \{1, 5\}, \{1, 6\}, \{1, 7\}, \{2, 3\}, \{2, 4\}, \{2, 5\}, \{2, 6\}, \{2, 7\}, \{3, 4\}, \{3, 5\}, \{3, 6\}, \{3, 7\}, \{4, 5\}, \{4, 6\}, \{4, 7\}, \{5, 6\}, \{5, 7\}, \{6, 7\} \right\}.$$ And since we have 77 vertices, 1≤r≤71 \le r \le 7. We need to find the sum of f(r,S)f(r, S) over all possible pairs of rr and SS.

Below we have listed the value of f(r,S)f(r, S) for some combinations of rr and SS.

  • r=1r = 1, S=3,7S = {3, 7}. The value of f(r,S)f(r, S) is 55 and the corresponding subtree is 2,3,4,6,7{2, 3, 4, 6, 7}.
  • r=1r = 1, S=5,4S = {5, 4}. The value of f(r,S)f(r, S) is 77 and the corresponding subtree is 1,2,3,4,5,6,7{1, 2, 3, 4, 5, 6, 7}.
  • r=1r = 1, S=4,6S = {4, 6}. The value of f(r,S)f(r, S) is 33 and the corresponding subtree is 4,6,7{4, 6, 7}.

第二个示例中的树如下所示:

给定树中大小为 22 的子集共有 2121 个。因此,

S∈{{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{2,3},{2,4},{2,5},{2,6},{2,7},{3,4},{3,5},{3,6},{3,7},{4,5},{4,6},{4,7},{5,6},{5,7},{6,7}}.S \in \left\{\{1, 2\}, \{1, 3\}, \{1, 4\}, \{1, 5\}, \{1, 6\}, \{1, 7\}, \{2, 3\}, \{2, 4\}, \{2, 5\}, \{2, 6\}, \{2, 7\}, \{3, 4\}, \{3, 5\}, \{3, 6\}, \{3, 7\}, \{4, 5\}, \{4, 6\}, \{4, 7\}, \{5, 6\}, \{5, 7\}, \{6, 7\} \right\}.

又因该树有 77 个顶点,故 1≤r≤71 \le r \le 7。我们需要对所有可能的 (r,S)(r, S) 对,求 f(r,S)f(r, S) 的总和。

下面列出了若干组 (r,S)(r, S) 对应的 f(r,S)f(r, S) 的值:

  • r=1r = 1,S={3,7}S = \{3, 7\}:f(r,S)=5f(r, S) = 5,对应的子树为 {2,3,4,6,7}\{2, 3, 4, 6, 7\}。
  • r=1r = 1,S={5,4}S = \{5, 4\}:f(r,S)=7f(r, S) = 7,对应的子树为 {1,2,3,4,5,6,7}\{1, 2, 3, 4, 5, 6, 7\}。
  • r=1r = 1,S={4,6}S = \{4, 6\}:f(r,S)=3f(r, S) = 3,对应的子树为 {4,6,7}\{4, 6, 7\}。

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

首页