Summer Driving

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

요약
트리에서 R에서 출발해 앨리스는 매 턴 정확히 A개의 새 간선을, 밥은 최대 B개의 간선을 이동하는 게임을 할 때 최적 플레이로 도착하는 도시를 구한다.
난이도

어려움10점 중 9점

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

문제

In Ontario, there are NN cities numbered from 11 to NN. There are N−1N -1 roads numbered from 11 to N−1N - 1, where the ii-th road connects city u_iu\_i and city v_iv\_i. It is possible to travel from any city to any other city using these roads.

Alice and Bob are travelling together, starting at city RR. To make their driving experience more interesting, they devise the following game.

Alice and Bob will alternate turns, starting with Alice. On Alice’s turn, she must drive along exactly AA distinct roads that they have never traversed before in either direction. On Bob’s turn, he must drive along up to BB distinct roads (possibly zero), but some of these roads may have been traversed before.

Eventually, it will be Alice’s turn, but it will be impossible for her to drive along exactly AA distinct roads that they have never used before. When this happens, the game enters a final phase before Alice does any more driving. In this final phase, Bob drives along up to BB distinct roads (possibly zero) that they have never traversed before in either direction.

Alice wants to end up in a city with as large a number as possible, while Bob wants to end up in a city with a small number. What is the city that Alice and Bob end their journey in when they both play optimally?

입력

The first line of input contains four space-separated integers, NN, RR, AA, and BB (1≤R,A,B≤N1 ≤ R, A, B ≤ N).

The next N−1N - 1 lines of input each contain two space-separated 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), describing a road.

출력

Output the city that Alice and Bob end their journey in, assuming they both play optimally.

예제2

  1. 예제 1

    입력
    9 6 2 1
    1 3
    1 6
    2 4
    2 5
    2 7
    3 9
    4 6
    4 8
    
    예상 출력
    2
    
  2. 예제 2

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