QOJ.ac

QOJ

Limite de temps : 10 s Limite de mémoire : 1024 MB Points totaux : 100 Difficulté: [afficher]

#2279. 水井

Statistiques

在美丽的韦莱比特山上,有 $N$ 个避难所。恰好有 $N-1$ 对避难所通过徒步路径相连,使得任意两个避难所之间都可以通过这些路径到达。

仙女维拉非常喜欢徒步,她走完连接两个避难所的路径需要恰好一天。她可以使用魔法在每天开始时出现在任意一个避难所,然后花费接下来的 $K-1$ 天进行徒步,要求在徒步过程中从不重复访问同一个避难所。因此,在一次徒步中,维拉恰好访问 $K$ 个避难所。

维拉在徒步时会感到口渴,因此她希望在一些避难所设置水井。在她的任何一次可能的徒步中,她都希望恰好访问一个设有水井的避难所。

你的任务是确定是否存在一个避难所子集,可以在其中设置水井以满足维拉的特殊愿望。此外,你需要计算满足条件的子集数量,结果对 $10^9 + 7$ 取模。

形式化地说,给定一棵包含 $N$ 个顶点的树和一个正整数 $K$,确定是否存在一个顶点子集,使得任何包含恰好 $K$ 个顶点的路径都恰好包含该子集中的一个顶点。此外,你还需要求出满足条件的子集数量,结果对 $10^9 + 7$ 取模。

输入格式

第一行包含两个整数 $N$ 和 $K$ ($2 \le K \le N$)。

接下来的 $N-1$ 行描述徒步路径。第 $i$ 行包含两个空格分隔的整数 $a_i$ 和 $b_i$ ($1 \le a_i, b_i \le N$),表示避难所 $a_i$ 和 $b_i$ 之间的一条徒步路径。

保证这些路径构成一棵树。

输出格式

第一行输出 "YES"(如果存在满足维拉条件的避难所子集),否则输出 "NO"。

第二行输出满足维拉条件的避难所子集的数量,结果对 $10^9 + 7$ 取模。

子任务

子任务 分值 数据范围
1 30 $2 \le K \le N \le 200$
2 20 $2 \le K \le N \le 10\,000$
3 20 $2 \le K \le N \le 500\,000$
4 30 $2 \le K \le N \le 1\,500\,000$

如果你的程序输出了正确的第一行,但未能提供正确的第二行,则该测试点将获得该子任务分值的 60%。

每个子任务的得分为该子任务中所有测试点得分的最小值。

样例

样例输入 1

4 2
3 4
3 1
2 3

样例输出 1

YES
2

样例输入 2

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

样例输出 2

NO
0

样例输入 3

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

样例输出 3

YES
10

说明

第一个样例的说明:合法的避难所子集为 $\{3\}$ 和 $\{1, 2, 4\}$。

第三个样例的说明:图中只有一条长度为 5 的路径,该路径包含节点 3、6、4、2 和 5。这些节点中必须恰好有一个在所求子集中,而节点 1 是否在子集中没有影响。

因此,合法的避难所子集为 $\{3\}, \{1, 3\}, \{6\}, \{1, 6\}, \{4\}, \{1, 4\}, \{2\}, \{1, 2\}, \{5\}, \{1, 5\}$。

Figure 1. Visual representation of the tree structures for the three sample inputs.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.