結果

問題 No.1244 Black Segment
ユーザー brthyyjpbrthyyjp
提出日時 2022-03-24 18:55:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 621 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 82,548 KB
実行使用メモリ 96,504 KB
最終ジャッジ日時 2024-04-21 04:11:30
合計ジャッジ時間 7,380 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
53,888 KB
testcase_01 AC 45 ms
53,760 KB
testcase_02 AC 46 ms
53,632 KB
testcase_03 AC 46 ms
53,632 KB
testcase_04 AC 47 ms
53,632 KB
testcase_05 AC 46 ms
53,888 KB
testcase_06 AC 50 ms
54,016 KB
testcase_07 AC 52 ms
54,016 KB
testcase_08 AC 54 ms
53,888 KB
testcase_09 AC 53 ms
54,144 KB
testcase_10 AC 54 ms
53,888 KB
testcase_11 AC 52 ms
54,016 KB
testcase_12 AC 53 ms
53,376 KB
testcase_13 AC 87 ms
69,888 KB
testcase_14 AC 136 ms
80,844 KB
testcase_15 AC 75 ms
69,396 KB
testcase_16 AC 114 ms
81,328 KB
testcase_17 AC 72 ms
67,328 KB
testcase_18 AC 145 ms
84,888 KB
testcase_19 AC 148 ms
89,484 KB
testcase_20 AC 187 ms
88,236 KB
testcase_21 AC 155 ms
88,376 KB
testcase_22 AC 176 ms
88,016 KB
testcase_23 AC 167 ms
88,348 KB
testcase_24 AC 177 ms
88,824 KB
testcase_25 AC 158 ms
89,196 KB
testcase_26 AC 180 ms
88,564 KB
testcase_27 AC 150 ms
89,384 KB
testcase_28 AC 199 ms
89,376 KB
testcase_29 AC 181 ms
89,228 KB
testcase_30 AC 189 ms
89,100 KB
testcase_31 AC 173 ms
89,180 KB
testcase_32 AC 197 ms
89,668 KB
testcase_33 AC 177 ms
89,164 KB
testcase_34 AC 171 ms
93,368 KB
testcase_35 AC 134 ms
96,504 KB
testcase_36 AC 173 ms
91,476 KB
testcase_37 AC 167 ms
90,216 KB
testcase_38 AC 155 ms
88,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

from collections import deque
INF = 10**18

n, m, a, b = map(int, input().split())
edge = [[] for i in range(n+2)]
for i in range(m):
    l, r = map(int, input().split())
    r += 1
    l = max(l, a)
    r = min(r, b+1)
    edge[l].append(r)
    edge[r].append(l)

q = deque([])
q.append(a)
dist = [INF]*(n+2)
dist[a] = 0
while q:
    v = q.popleft()
    for u in edge[v]:
        if dist[u] != INF:
            continue
        dist[u] = dist[v]+1
        q.append(u)

ans = dist[b+1]
if ans < INF:
    print(ans)
else:
    print(-1)
0