In Ontario, there are
cities numbered from 1 to
.
There are
roads numbered from 1 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?
Input Specification
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 Specification
Output the city that Alice and Bob end their journey in, assuming they both play optimally.
Sample Input 1
Copy
9 6 2 1
1 3
1 6
2 4
2 5
2 7
3 9
4 6
4 8
Sample Output 1
Copy
2
Explanation for Sample 1
On Alice's first turn, she has three options: Drive to city
,
, or
.
If Alice drives to city
, Bob can choose not to drive on any roads in his turn.
Then, it will be impossible for Alice to drive along
distinct roads that were never traversed before, so the game enters the final phase.
Bob can choose not to drive on any roads during this final phase, ending in city
.
If Alice drives to city
, Bob can choose to drive
road to city
.
Then, it will be impossible for Alice to drive along
distinct roads that were never traversed before, so the game enters the final phase.
Bob's only option is to not drive on any roads during this final phase, ending in city
.
If Alice drives to city
, Bob can choose to drive
road to city
.
Then, Alice can drive to either city
or
.
In both cases, Bob can then drive
road to city
.
Alice can no longer drive along
distinct roads that were never traversed before, so the game enters the final phase.
Bob can choose not to drive on any roads during this final phase, ending in city
.
In all cases, Bob can force the game to end in city
or
.
Bob cannot force the game to end in city
, so under optimal play, the game ends in city
.
Sample Input 2
Copy
7 2 3 2
2 7
7 3
3 1
1 4
4 5
5 6
Sample Output 2
Copy
3
Comments