Logo
(追記) (追記ここまで)

27599번 - Parmigiana With Seafood 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB65232035.714%

문제

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 $n$ possible ingredients, labeled from 1ドル$ to $n$. The higher the label, the closer the ingredient is to being seafood. The ingredients are connected by $n - 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 $x,ドル that is an ingredient currently connected to at most one other ingredient, and remove it from the tree. If the terminal ingredient $x$ 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 $n$ (2ドル ≤ n ≤ 100,000円$) — the number of ingredients.

Each of the following $n - 1$ lines contain two integers $u_i$ and $v_i$ (1ドル ≤ u_i , v_i ≤ n,ドル $u_i \ne v_i$) — the ingredients that the $i$-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

Alessandro can choose terminal ingredient 4ドル$ in the first turn. This ingredient is added to the recipe. Since 4ドル$ is the maximum label of an ingredient, the taste is 4ドル$ regardless of the choices that follow.

예제 입력 2

5
1 5
5 3
3 4
4 2

예제 출력 2

3

Bianca can make sure that neither ingredient 4ドル$ nor 5ドル$ are included in the recipe, in which case Alessandro can include 3ドル$. Thus, the taste is 3ドル$.

힌트

출처

ICPC > Regionals > Europe > Southwestern European Regional Contest > SWERC 2022-2023 G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /