QOJ.ac

QOJ

时间限制: 2 s 内存限制: 2048 MB 总分: 100

#5651. 海鲜帕尔马干酪茄子

统计

“Parmigiana di melanzane” 是一道典型的意大利菜。Alessandro 和 Bianca 对这道菜的口味有着截然不同的看法:Alessandro 喜欢吃海鲜口味的 Parmigiana,而 Bianca 认为这简直是暴殄天物!为了决定在准备的菜肴中加入哪些配料,他们玩起了以下游戏。

共有 $n$ 种可能的配料,编号从 $1$ 到 $n$。编号越大,该配料越接近海鲜。这些配料通过 $n-1$ 条边连接,构成了一棵树。Alessandro 和 Bianca 轮流进行操作,Alessandro 先手。他们轮流选择一个终端配料 $x$(即当前连接边数不超过 $1$ 的配料),并将其从树中移除。如果该终端配料 $x$ 是由 Alessandro 选择的,它就会被加入菜肴中;如果是由 Bianca 选择的,它就会被丢弃。

Parmigiana 的口味由菜肴中配料的最大编号来衡量。Alessandro 希望最大化口味值,而 Bianca 希望最小化口味值。如果两人都采取最优策略,最终的口味值是多少?

输入格式

第一行包含一个整数 $n$ ($2 \le n \le 100\,000$),表示配料的数量。

接下来的 $n-1$ 行,每行包含两个整数 $u_i$ 和 $v_i$ ($1 \le u_i, v_i \le n, u_i \neq v_i$),表示第 $i$ 条边连接的配料。

保证这些边构成一棵树(即任意两个配料之间通过边相连,可能通过中间节点间接相连)。

输出格式

输出两人均采取最优策略时的口味值。

样例

样例输入 1

4
1 2
1 3
1 4

样例输出 1

4

说明

Alessandro 可以在第一步选择终端配料 $4$。该配料被加入菜肴。由于 $4$ 是所有配料中的最大编号,因此无论后续如何选择,口味值均为 $4$。

样例输入 2

5
1 5
5 3
3 4
4 2

样例输出 2

3

说明

Bianca 可以确保配料 $4$ 和 $5$ 都不会被加入菜肴,在这种情况下,Alessandro 可以加入 $3$。因此,口味值为 $3$。

Figure 1. Shrimp

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.