Breadth First Search 0-1-2#10058

Breadth First Search 0-1-2

1 second
128 megabytes
Very easy

Undirected graph is given. The weights of its edges can be , , or only. Find the shortest distance from source to destination .

Input

First line contains four integers: number of vertices , number of edges (n, m \leq 10^5), source and destination (1 \leq s, d \leq n). Each of the next lines contains three integers , and describing an undirected edge (, ) with weight (0 \leq w \leq 2).

Output

Print the shortest distance from to .

prb10058.gif

Examples

Example 1

Loading
Loading