結果

問題 No.1244 Black Segment
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-10-02 22:25:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 90,868 KB
最終ジャッジ日時 2023-09-24 21:28:38
合計ジャッジ時間 9,748 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
79,956 KB
testcase_01 AC 107 ms
79,856 KB
testcase_02 AC 102 ms
79,892 KB
testcase_03 AC 105 ms
80,100 KB
testcase_04 AC 105 ms
79,820 KB
testcase_05 AC 105 ms
79,780 KB
testcase_06 AC 108 ms
79,880 KB
testcase_07 AC 107 ms
79,744 KB
testcase_08 AC 106 ms
79,864 KB
testcase_09 AC 108 ms
79,128 KB
testcase_10 AC 109 ms
79,908 KB
testcase_11 AC 109 ms
78,972 KB
testcase_12 AC 106 ms
79,880 KB
testcase_13 AC 127 ms
81,020 KB
testcase_14 AC 166 ms
86,732 KB
testcase_15 AC 123 ms
81,256 KB
testcase_16 AC 170 ms
86,888 KB
testcase_17 AC 122 ms
81,348 KB
testcase_18 AC 195 ms
87,996 KB
testcase_19 AC 231 ms
89,000 KB
testcase_20 AC 229 ms
89,360 KB
testcase_21 AC 204 ms
89,488 KB
testcase_22 AC 240 ms
89,448 KB
testcase_23 AC 244 ms
89,548 KB
testcase_24 AC 229 ms
89,632 KB
testcase_25 AC 232 ms
89,600 KB
testcase_26 AC 222 ms
89,472 KB
testcase_27 AC 224 ms
90,156 KB
testcase_28 AC 236 ms
89,472 KB
testcase_29 AC 222 ms
89,360 KB
testcase_30 AC 227 ms
89,636 KB
testcase_31 AC 238 ms
89,452 KB
testcase_32 AC 237 ms
89,668 KB
testcase_33 AC 239 ms
89,660 KB
testcase_34 AC 254 ms
90,096 KB
testcase_35 AC 207 ms
90,812 KB
testcase_36 AC 224 ms
90,648 KB
testcase_37 AC 232 ms
90,868 KB
testcase_38 AC 225 ms
90,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1244

ダイクストラ
右に進む = 黒に塗る
左に進む = 白で塗りなおす
で解けるはず

"""

from sys import stdin
import sys
from collections import deque

N,M,A,B = map(int,stdin.readline().split())

lis = [ [] for i in range(10**5+10) ]

for i in range(M):

    l,r = map(int,stdin.readline().split())
    lis[l].append(r+1)
    lis[r+1].append(l)

d = [float("inf")] * (10**5+10)

q = deque([])
for i in range(A+1):
    if len(lis[i]) > 0:
        q.append(i)
        d[i] = 0

while len(q):

    now = q.popleft()

    for nex in lis[now]:
        if d[nex] > d[now] + 1:
            d[nex] = d[now] + 1
            q.append(nex)

ans = min(d[B+1:])

if ans == float("inf"):
    print (-1)
else:
    print (ans)
0