Summer Driving
시간 제한6초메모리 제한1024 MB
트리에서 R에서 출발해 앨리스는 매 턴 정확히 A개의 새 간선을, 밥은 최대 B개의 간선을 이동하는 게임을 할 때 최적 플레이로 도착하는 도시를 구한다.
문제
In Ontario, there are cities numbered from to . There are roads numbered from to , where the -th road connects city and city . It is possible to travel from any city to any other city using these roads.
Alice and Bob are travelling together, starting at city . 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 distinct roads that they have never traversed before in either direction. On Bob’s turn, he must drive along up to 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 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 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, , , , and ().
The next lines of input each contain two space-separated integers and (, ), describing a road.
출력
Output the city that Alice and Bob end their journey in, assuming they both play optimally.