아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Parmigiana With Seafood

시간 제한2초메모리 제한1024 MB

요약
트리에서 두 사람이 번갈아 잎을 제거하며, 알레산드로가 고른 재료는 남기고 비앙카가 고른 재료는 버린다. 알레산드로가 확보할 수 있는 가장 큰 번호를 구한다.
난이도

보통10점 중 7점

유형
트리, 게임 이론, 그리디, DFS
정답자
아직 제출이 없습니다

문제

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?

입력

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

Each of the following n−1n - 1 lines contain two integers u_iu\_i and v_iv\_i (1≤u_i,v_i≤n1 ≤ u\_i , v\_i ≤ n, u_i≠v_iu\_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.

예제2

  1. 예제 1

    입력
    4
    1 2
    1 3
    1 4
    
    예상 출력
    4
    
  2. 예제 2

    입력
    5
    1 5
    5 3
    3 4
    4 2
    
    예상 출력
    3