문제
Problem 1: Cow Routing [Richard Peng, 2015]
Tired of the cold winter weather on her farm, Bessie the cow plans to fly to a warmer destination for vacation. Unfortunately, she discovers that only one airline, Air Bovinia, is willing to sell tickets to cows, and that these tickets are somewhat complicated in structure.
Air Bovinia owns N planes
Bessie would like to find the cheapest way to travel from her farm (in city A) to her tropical destination (city B). Since she does not want to be confused by a complicated itinerary, she wants to use only a single route. Please help her decide what is the minimum cost she must pay.
입력
The first line of input contains A, B, and N, separated by spaces. The next 2N lines describe the available routes, in two lines per route. The first line contains the cost of using the route (an integer in the range
출력
Output the minimum cost of a single route Bessie can use to travel from city A to city B. If there is no such route, output -1.
예제1
1 2 3
3 3
3 2 1
4 4
2 1 4 3
8 5
4 1 7 8 2
8