Under construction

Still being built. Things may change

Prime Routing

Time limit2sMemory limit512 MB

Summary
Find the minimum prime length of a walk from S to T in an undirected graph, where cables may be reused; print -1 if impossible.
Level

Medium7 of 10

Topics
Graph, BFS, Number theory, Shortest path
Solved
No attempts yet

Problem

Fox Jiro is one of the staff members of the ACM-ICPC 2018 Asia Yokohama Regional Contest and is responsible for designing the network for the venue of the contest. His network consists of NN computers, which are connected by MM cables. The ii-th cable connects the aia_i-th computer and the bib_i-th computer, and it carries data in both directions. Your team will use the SS-th computer in the contest, and a judge server is the TT-th computer.

He decided to adjust the routing algorithm of the network to maximize the performance of the contestants through the magical power of prime numbers. In this algorithm, a packet (a unit of data carried by the network) is sent from your computer to the judge server passing through the cables a prime number of times if possible. If it is impossible, the contestants cannot benefit by the magical power of prime numbers. To accomplish this target, a packet is allowed to pass through the same cable multiple times.

You decided to write a program to calculate the minimum number of times a packet from SS to TT needed to pass through the cables. If the number of times a packet passes through the cables cannot be a prime number, print −1-1.

Input

The input consists of a single test case, formatted as follows.

$N$ $M$ $S$ $T$ $a_1$ $b_1$ $\vdots$ $a_M$ $b_M$

The first line consists of four integers NN, MM, SS, and TT (2≤N≤1052 \leq N \leq 10^5, 1≤M≤1051 \leq M \leq 10^5, 1≤S,T≤N1 \leq S, T \leq N, S≠TS \neq T). The ii-th line of the following MM lines consists of two integers aia_i and bib_i (1≤ai<bi≤N1 \leq a_i < b_i \leq N), which means that the ii-th cable connects the aia_i-th computer and the bib_i-th computer in the network. You can assume that the network satisfies the following conditions.

  • The network has no multi-edge, i.e., (ai,bi)≠(aj,bj)(a_i, b_i) \neq (a_j, b_j) for all ii, jj (1≤i<j≤M1 \leq i < j \leq M).
  • The packets from NN computers are reachable to TT by passing through some number of cables. The number is not necessarily a prime.

Output

If there are ways such that the number of times a packet sent from SS to TT passes through the cables is a prime number, print the minimum prime number of times in one line. Otherwise, print −1-1.

Examples4

  1. Example 1

    Input
    5 5 1 5
    1 2
    1 4
    2 3
    3 4
    3 5
    
    Expected output
    3
    
  2. Example 2

    Input
    5 4 1 5
    1 2
    2 3
    3 4
    4 5
    
    Expected output
    -1
    
  3. Example 3

    Input
    2 1 1 2
    1 2
    
    Expected output
    3
    
  4. Example 4

    Input
    3 3 1 2
    1 2
    1 3
    2 3
    
    Expected output
    2