CF1776M.Parmigiana With Seafood

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The "Parmigiana di melanzane" is a typical Italian dish. Alessandro and Bianca have very different tastes when it comes to it: Alessandro loves to eat Parmigiana with seafood, but Bianca thinks it is an atrocity! To decide which ingredients to include in the dish they prepare, they play the following game.

There are nn possible ingredients, labeled from 11 to nn. The higher the label, the closer the ingredient is to being seafood. The ingredients are connected by n−1n - 1 edges, in such a way as to form a tree. Alessandro and Bianca take turns, with Alessandro going first. They alternately choose a terminal ingredient xx, that is an ingredient currently connected to at most one other ingredient, and remove it from the tree. If the terminal ingredient xx was chosen by Alessandro, it goes in the recipe; if it was chosen by Bianca, it is discarded.

The taste of the Parmigiana is measured as the maximum label of an ingredient in the recipe. Alessandro wants to maximize the taste, while Bianca wants to minimize the taste. If both play optimally, what is the taste of the Parmigiana?

“帕尔马干酪茄子”是一道经典的意大利菜肴。亚历山德罗和比安卡对这道菜的口味偏好截然不同:亚历山德罗非常喜欢在帕尔马干酪茄子中加入海鲜,而比安卡则认为这是种亵渎!为了决定他们所准备的这道菜中应包含哪些食材,两人玩起了如下游戏。

共有 nn 种可能的食材,编号为 11 到 nn。编号越大,该食材越接近海鲜。这些食材通过 n−1n - 1 条边相互连接,构成一棵树。亚历山德罗和比安卡轮流进行操作,亚历山德罗先行。两人轮流选择一个叶节点食材 xx(即当前至多只与另一食材相连的食材),并将其从树中移除。若该叶节点食材 xx 由亚历山德罗选出,则它被加入食谱;若由比安卡选出,则它被丢弃。

帕尔马干酪茄子的“美味度”定义为食谱中所有食材编号的最大值。亚历山德罗希望最大化美味度,而比安卡则希望最小化美味度。若双方均以最优策略进行游戏,则最终帕尔马干酪茄子的美味度是多少?

输入格式

The first line contains an integer nn (2≤n≤100 0002\le n \le 100\,000) — the number of ingredients.

Each of the following n−1n-1 lines contain two integers uiu_i and viv_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \ne v_i) — the ingredients that the ii-th edge connects.

It is guaranteed that the edges form a tree (i.e., any pair of ingredients is connected by the edges, possibly indirectly).

第一行包含一个整数 nn(2≤n≤100 0002\le n \le 100\,000)—— 食材的数量。

接下来的 n−1n-1 行中,每行包含两个整数 uiu_i 和 viv_i(1≤ui,vi≤n1 \le u_i, v_i \le n,且 ui≠viu_i \ne v_i)—— 表示第 ii 条边所连接的两种食材。

保证这些边构成一棵树(即任意两种食材之间都可通过边(可能间接)相连)。

输出格式

Print the value of the taste if both Alessandro and Bianca play optimally.

如果亚历山德罗和比安卡都采取最优策略,输出“口味值”的数值。

输入输出样例

  • 输入#1

    4
    1 2
    1 3
    1 4

    输出#1

    4
  • 输入#2

    5
    1 5
    5 3
    3 4
    4 2

    输出#2

    3

说明/提示

In the first sample, Alessandro can choose terminal ingredient 44 in the first turn. This ingredient is added to the recipe. Since 44 is the maximum label of an ingredient, the taste is 44 regardless of the choices that follow.

In the second sample, Bianca can make sure that neither ingredient 44 nor 55 are included in the recipe, in which case Alessandro can include 33. Thus, the taste is 33.

在第一个样例中,亚历山德罗可以在第一轮选择终端原料 44。该原料将被加入食谱中。由于 44 是所有原料编号中的最大值,因此无论后续如何选择,最终的风味值均为 44。

在第二个样例中,比安卡可以确保原料 44 和 55 均不被加入食谱,此时亚历山德最多只能加入原料 33。因此,最终的风味值为 33。

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

首页