Shortest Path BFS

Programming Interview Hard 5 views
Back to Questions
Next Graph Shortest Path Class Hard N

Problem Description

Input provides {x}. Implement bfs to output shortest distance (edges count) or -1.

Input Format

First line n m. Next m lines u v. Last line s t.

Output Format

One integer distance.

Sample Test Case

Input:
5 5 1 2 2 3 3 4 4 5 1 5 1 4
Output:
3

Constraints

1

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Next