#P1700. [USACO19OPEN] Milk Factory B
[USACO19OPEN] Milk Factory B
Problem Description
The milk business is booming. Farmer John's milk factory has processing stations numbered (), and passages, each connecting two processing stations. (Building passages is expensive, so Farmer John chose to use the minimum number of passages such that starting from any processing station, it was possible to reach all other processing stations.)
To innovate and improve efficiency, Farmer John installed conveyor belts on each passage. Unfortunately, by the time he realized the conveyor belts were one-way, it was too late, and now each passage can only be traveled in one direction. So now it is no longer true that starting from every processing station, you can reach all other processing stations.
However, Farmer John believes things may not be a complete failure, as long as there still exists at least one processing station such that starting from every other processing station, it is possible to reach processing station . Note that going from any other processing station to processing station may pass through some intermediate stations between and . Please help Farmer John determine whether such a processing station exists.
Input Format
The first line of input contains an integer , the number of processing stations. The following lines each contain two space-separated integers and , satisfying and . This indicates there is a conveyor belt that moves from processing station to processing station , and movement is only allowed in the direction from to .
Output Format
If there exists a processing station such that it is reachable from every other processing station, output the smallest such . Otherwise, output .
3
1 2
3 2
2
Hint
Translated by ChatGPT 5