QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 16 MB 總分: 100

#11880. 洞穴

统计

Byteotia 有一个洞穴,由 $n$ 个房间和连接它们的走廊组成。走廊的布局使得每两个房间之间都存在唯一的路径。Hansel 在其中一个房间里藏了宝藏,但他不会告诉 Gretel 是哪一个。Gretel 很想知道宝藏的位置,于是她向 Hansel 询问各个房间。当她猜对时,Hansel 会告诉她猜对了;当她猜错时,Hansel 会告诉她从当前房间出发,哪条路通往藏有宝藏的房间。

请编写一个程序:

  • 从标准输入读取洞穴的描述;
  • 计算在最坏情况下,Gretel 为了确定宝藏藏在哪个房间所需询问的最少次数;
  • 将结果输出到标准输出。

输入格式

标准输入的第一行包含一个正整数 $n$ ($1 \le n \le 50\,000$),表示洞穴中房间的数量。房间编号从 $1$ 到 $n$。接下来的 $n-1$ 行描述了连接房间的走廊,每行包含一对不同的正整数 $a$ 和 $b$ ($1 \le a, b \le n$),中间用空格隔开,表示房间 $a$ 和 $b$ 之间有一条走廊。

输出格式

程序应在标准输出中输出一个整数,即在最坏情况下 Gretel 所需询问的最少次数(即假设 Gretel 采取最优策略进行询问,但宝藏藏在需要询问次数最多的那个房间里)。

样例

输入 1

5
1 2
2 3
4 3
5 3

输出 1

2

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.