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

18551번 - 5-Path 다국어

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

문제

You are given a list of edges of an undirected graph. There are two special nodes in the graph: a and b. Find the minimum size of a prefix of this list such that a graph represented by this prefix includes a simple path of 5 edges between nodes a and b.

입력

The first line of input contains two integers n and m: the number of nodes and the number of edges in the graph, respectively.

Each of the following m lines contains two integers vi and ui which describe two endpoints of an edge (1 ≤ vi, ui ≤ n).

The last line contains two integers a and b: the numbers of special nodes (a 6= b, 1 ≤ a, b ≤ n).

The graph has no multiple edges and no self-loops.

출력

If there is a simple path of 5 edges in the graph represented by the given edge list, output the answer to the problem. Otherwise, output −1.

제한

예제 입력 1

10 9
1 6
6 9
9 10
10 3
3 2
2 7
7 5
5 8
8 4
6 7

예제 출력 1

6

예제 입력 2

10 10
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
10 2
10 3
1 10

예제 출력 2

-1

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2019 > Day 8: Petrozavodsk SU Contest E번

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

출처

대학교 대회

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

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