Logo
(追記) (追記ここまで)

16835번 - Prime Routing 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB28232385.185%

문제

Fox Jiro is one of the staffs 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 $N$ computers, which are connected by $M$ cables. The $i$-th cable connects the $a_i$-th computer and the $b_i$-th computer, and it carries data in both directions. Your team will use the $S$-th computer in the contest, and a judge server is the $T$-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 $S$ to $T$ needed to pass through the cables. If the number of times a packet passes through the cables cannot be a prime number, print $-1$.

입력

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 $N,ドル $M,ドル $S,ドル and $T$ (2ドル \leq N \leq 10^5,ドル 1ドル \leq M \leq 10^5,ドル 1ドル \leq S, T \leq N,ドル $S \neq T$). The $i$-th line of the following $M$ lines consists of two integers $a_i$ and $b_i$ (1ドル \leq a_i < b_i \leq N$), which means the $i$-th cables connects the $a_i$-th computer and the $b_i$-th computer in the network. You can assume that the network satisfies the following conditions.

  • The network has no multi-edge, i.e., $(a_i, b_i) \neq (a_j, b_j)$ for all $i,ドル $j$ (1ドル \leq i \lt j \leq M$).
  • The packets from $N$ computers are reachable to $T$ by passing through some number of cables. The number is not necessarily a prime.

출력

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

제한

예제 입력 1

5 5 1 5
1 2
1 4
2 3
3 4
3 5

예제 출력 1

3

예제 입력 2

5 4 1 5
1 2
2 3
3 4
4 5

예제 출력 2

-1

예제 입력 3

2 1 1 2
1 2

예제 출력 3

3

예제 입력 4

3 3 1 2
1 2
1 3
2 3

예제 출력 4

2

힌트

출처

Contest > ICPC Japanese Alumni Group > JAG Summer Camp > JAG Summer Camp 2018 Day 3 J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /