結果

問題 No.1244 Black Segment
ユーザー rlangevinrlangevin
提出日時 2023-11-14 08:59:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 90,192 KB
最終ジャッジ日時 2023-11-14 08:59:32
合計ジャッジ時間 8,691 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,608 KB
testcase_01 AC 42 ms
55,608 KB
testcase_02 AC 41 ms
55,608 KB
testcase_03 AC 42 ms
55,608 KB
testcase_04 AC 42 ms
55,608 KB
testcase_05 AC 41 ms
55,608 KB
testcase_06 AC 41 ms
55,608 KB
testcase_07 AC 41 ms
55,608 KB
testcase_08 AC 41 ms
55,608 KB
testcase_09 AC 42 ms
55,608 KB
testcase_10 AC 42 ms
55,608 KB
testcase_11 AC 41 ms
55,608 KB
testcase_12 AC 41 ms
55,608 KB
testcase_13 AC 64 ms
68,728 KB
testcase_14 AC 110 ms
78,160 KB
testcase_15 AC 69 ms
68,696 KB
testcase_16 AC 110 ms
78,288 KB
testcase_17 AC 61 ms
68,864 KB
testcase_18 AC 163 ms
85,852 KB
testcase_19 AC 182 ms
86,344 KB
testcase_20 AC 183 ms
87,700 KB
testcase_21 AC 151 ms
86,580 KB
testcase_22 AC 222 ms
87,560 KB
testcase_23 AC 194 ms
88,116 KB
testcase_24 AC 190 ms
88,112 KB
testcase_25 AC 182 ms
88,124 KB
testcase_26 AC 172 ms
87,876 KB
testcase_27 AC 177 ms
88,656 KB
testcase_28 AC 204 ms
88,656 KB
testcase_29 AC 176 ms
88,400 KB
testcase_30 AC 180 ms
88,536 KB
testcase_31 AC 188 ms
88,792 KB
testcase_32 AC 193 ms
88,656 KB
testcase_33 AC 199 ms
88,920 KB
testcase_34 AC 231 ms
89,424 KB
testcase_35 AC 163 ms
89,936 KB
testcase_36 AC 184 ms
89,296 KB
testcase_37 AC 180 ms
90,192 KB
testcase_38 AC 185 ms
89,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from collections import deque
inf = 10 ** 18
def bfs(G, s, N):
    Q = deque([])
    dist = [inf] * N
    par = [inf] * N
    for i in range(s):
        dist[i] = 0
        Q.append(i)

    while Q:
        u = Q.popleft()
        for v in G[u]:
            if dist[v] != inf:
                continue
            dist[v] = dist[u] + 1
            par[v] = u
            Q.append(v)
            
    return dist

N, M, A, B = map(int, input().split())
G = [[] for i in range(N + 1)]
for i in range(M):
    L, R = map(int, input().split())
    L -= 1
    G[L].append(R)
    G[R].append(L)

D = bfs(G, A, N + 1)
ans = min(D[B:])
print(ans) if ans != inf else print(-1)
0