Transfer
Time limit2sMemory limit256 MB
Given hypertubes each connecting K stations totally, find the fewest stations visited traveling from station 1 to station N.
- Level
Medium5 of 10
- Topics
- BFS, Graph, Hash map, Implementation
- Solved
- No attempts yet
Problem
In the far future, the most widely used form of public transportation is the hypertube. A single hypertube directly connects stations to one another; that is, you can travel between any two stations on the same hypertube in a single move. Starting from station and arriving at station , find the minimum number of stations you visit. (Both the starting station and the destination station count as visited.)
Input
The first line contains the number of stations , the number of stations that one hypertube connects , and the number of hypertubes . (, )
Each of the next lines describes one hypertube. A line contains integers: the numbers of the stations that this hypertube connects to one another.
Output
Print the minimum number of stations visited on a trip from station to station . If station cannot be reached, print .