Kimi No Ichi Wa.
Time limit2sMemory limit256 MB
Given a special one-way line where every non-endpoint station balances in and out degree, find the meeting station closest to the start.
Problem
Taki and Mitsuha, riding the commuter train with the usual emptiness, spot each other through the windows. They recognize each other, but the two lines split and the distance grows. Both set off to find the other at once, and you want to know where they can meet, so you look for the station closest to the start of the line among all stations where a meeting can happen.
Their commuter tickets are special, so the line they can ride has these properties.
- Every railway between two stations is one way, and no railway joins a station to itself.
- Every station other than the start and the terminal has as many incoming railways as outgoing railways.
- The start is connected to exactly one outgoing railway, and the terminal to exactly one incoming railway.
- For any station, at most one route leaves it, visits each other station at most once, and comes back to it.
- There is a route from the start to every station, and a route from every station to the terminal.
Both want to meet as soon as possible, so neither of them ever stops moving. Riding any railway takes the same time, so say one ride costs time . A person who reaches the terminal gets off the train and leaves for work right away, so nobody can meet that person after that moment. Taki and Mitsuha are bound by a special tie, so they always meet when they are at the same station at the same time.
Given the line and the numbers of the stations where Taki and Mitsuha are now, print the number of the station closest to the start among the stations where they can meet. Distance here is the smallest number of railways on a route from the start to that station. If there is no such station, print MUSUBI.
Input
The first line has the number of stations and the number of railways . (, )
Each of the next lines has two integers and , meaning there is a railway from station to station . ()
The last line has two different integers and , the numbers of the stations where Taki and Mitsuha are now. ()
The input always satisfies the conditions above.
Output
On the first line, print the number of the station closest to the start among the stations where the two can meet. If they cannot meet, print MUSUBI.