QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 2048 MB Points totaux : 100

#1368. 第 K 大子树

Statistiques

给定一棵无根带标号树。子树是这棵树的一个连通子图。子树的大小是子树中节点的数量。如果两个子树中至少有一个节点属于其中一个而不属于另一个,则它们是不同的。最大的子树即为原树本身。

计算第 $K$ 小的非空子树的大小。

输入格式

输入的第一行包含两个整数 $n$ ($1 \le n \le 5,000$) 和 $K$ ($1 \le K \le 10^{18}$),其中 $n$ 是树的节点数,你需要寻找第 $K$ 小子树的大小。节点编号为 $1$ 到 $n$。

接下来的 $n - 1$ 行,每行包含一对整数 $u$ 和 $v$ ($1 \le u, v \le n, u \neq v$),表示节点 $u$ 和 $v$ 之间的一条无向边。所有边均不相同。保证这些边构成一棵树。

输出格式

输出一个整数,即输入树中第 $K$ 小的非空子树的节点数。如果给定的树中非空子树的数量少于 $K$ 个,则输出 $-1$。

样例

样例输入 1

2 1
1 2

样例输出 1

1

样例输入 2

2 3
1 2

样例输出 2

2

样例输入 3

5 10
1 2
2 3
3 4
4 5

样例输出 3

3

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.