Breadth First Search
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Given an undirected graph. Find the shortest distance between two specified vertices.
Input
The first line contains three positive integers and . Here, is the number of vertices in the graph, and are the initial and final vertices. The next lines provide the adjacency matrix of the graph. If the value at the -th element of the -th row is , there is an edge between vertex and vertex .
Output
Print the minimum distance from the initial vertex to the final vertex. If no path exists, print .
Examples
Input #1
Answer #1
Submissions 12K
Acceptance rate 43%