#C5318. Taco: Shortest Bus Route

    ID: 48954 Type: Default 1000ms 256MiB

Taco: Shortest Bus Route

Taco: Shortest Bus Route

You are given a network of bus stops numbered from 1 to \(n\) and bus lines connecting them. Each bus line operates in both directions. Your task is to determine the minimum number of bus lines required to travel from a given start bus stop \(s\) to a target bus stop \(t\). If no such route exists, output \(-1\). If \(s = t\), the answer is \(0\).

This problem can be modeled as finding the shortest path in an undirected graph \(G=(V,E)\), where \(V=\{1,2,\dots,n\}\) and each bus line \((u,v)\) corresponds to an edge connecting nodes \(u\) and \(v\).

inputFormat

The input is given from standard input (stdin) and has the following format:

n m
u1 v1
u2 v2
...
um vm
s t

Here, \(n\) is the number of bus stops, \(m\) is the number of bus lines. Each of the next \(m\) lines contains two integers \(u\) and \(v\) representing a bus line between stops \(u\) and \(v\). The last line contains two integers \(s\) and \(t\): the starting and target bus stops respectively.

outputFormat

Output a single integer to standard output (stdout) representing the minimum number of bus lines needed to travel from \(s\) to \(t\). If it is impossible to reach \(t\) from \(s\), output \(-1\).

## sample
5 4
1 2
2 3
3 4
4 5
1 5
4

</p>