CF1776M.Parmigiana With Seafood

普及/提高-

通过率:0%

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 n1n - 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?

输入格式

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

Each of the following n1n-1 lines contain two integers uiu_i and viv_i ( 1ui,vin1 \le u_i, v_i \le n , uiviu_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).

输出格式

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 .

首页