結果

問題 No.1244 Black Segment
ユーザー tktk_snsntktk_snsn
提出日時 2021-02-12 20:04:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 97,044 KB
最終ジャッジ日時 2023-09-27 01:15:10
合計ジャッジ時間 10,780 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
71,240 KB
testcase_01 AC 86 ms
71,612 KB
testcase_02 AC 87 ms
71,608 KB
testcase_03 AC 87 ms
71,696 KB
testcase_04 AC 87 ms
71,364 KB
testcase_05 AC 86 ms
71,240 KB
testcase_06 AC 86 ms
71,244 KB
testcase_07 AC 86 ms
71,516 KB
testcase_08 AC 85 ms
71,412 KB
testcase_09 AC 87 ms
71,660 KB
testcase_10 AC 87 ms
71,428 KB
testcase_11 AC 84 ms
71,252 KB
testcase_12 AC 86 ms
71,612 KB
testcase_13 AC 108 ms
77,724 KB
testcase_14 AC 147 ms
81,768 KB
testcase_15 AC 106 ms
77,888 KB
testcase_16 AC 162 ms
85,228 KB
testcase_17 AC 110 ms
77,552 KB
testcase_18 AC 173 ms
87,616 KB
testcase_19 AC 210 ms
95,148 KB
testcase_20 AC 215 ms
94,036 KB
testcase_21 AC 202 ms
93,920 KB
testcase_22 AC 234 ms
93,900 KB
testcase_23 AC 227 ms
93,668 KB
testcase_24 AC 208 ms
93,820 KB
testcase_25 AC 208 ms
94,680 KB
testcase_26 AC 198 ms
93,884 KB
testcase_27 AC 200 ms
94,336 KB
testcase_28 AC 212 ms
94,816 KB
testcase_29 AC 196 ms
93,956 KB
testcase_30 AC 211 ms
95,964 KB
testcase_31 AC 215 ms
94,136 KB
testcase_32 AC 220 ms
94,156 KB
testcase_33 AC 218 ms
93,916 KB
testcase_34 AC 247 ms
93,892 KB
testcase_35 AC 186 ms
97,044 KB
testcase_36 AC 193 ms
95,948 KB
testcase_37 AC 199 ms
96,200 KB
testcase_38 AC 203 ms
94,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**9

N, M, A, B = map(int, input().split())
source = 0
sink = N + 2
G = [[] for _ in range(N + 3)]
for _ in range(M):
    L, R = map(int, input().split())
    R += 1
    G[L].append((R, 1))
    G[R].append((L, 1))
for i in range(1, A + 1):
    G[source].append((i, 0))
for i in range(B + 1, N + 2):
    G[i].append((sink, 0))

d = [inf] * (N + 3)
d[source] = 0
q = deque([source])
while q:
    s = q.popleft()
    ds = d[s]
    for t, dt in G[s]:
        if d[t] >= inf:
            if dt == 0:
                d[t] = ds
                q.appendleft(t)
            else:
                d[t] = ds + dt
                q.append(t)

ans = d[sink]
if ans >= inf:
    ans = -1
print(ans)
0