結果

問題 No.1244 Black Segment
ユーザー ntudantuda
提出日時 2021-11-09 22:00:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 699 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 103,924 KB
最終ジャッジ日時 2023-08-12 06:06:51
合計ジャッジ時間 9,369 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,260 KB
testcase_01 AC 69 ms
71,132 KB
testcase_02 AC 69 ms
71,168 KB
testcase_03 AC 69 ms
71,260 KB
testcase_04 AC 70 ms
71,348 KB
testcase_05 AC 69 ms
71,332 KB
testcase_06 AC 69 ms
71,280 KB
testcase_07 AC 72 ms
71,380 KB
testcase_08 AC 70 ms
71,528 KB
testcase_09 AC 69 ms
71,336 KB
testcase_10 AC 69 ms
71,316 KB
testcase_11 AC 68 ms
71,172 KB
testcase_12 AC 67 ms
71,392 KB
testcase_13 AC 122 ms
78,460 KB
testcase_14 AC 196 ms
91,428 KB
testcase_15 AC 115 ms
78,376 KB
testcase_16 AC 203 ms
96,356 KB
testcase_17 AC 105 ms
77,904 KB
testcase_18 AC 178 ms
90,344 KB
testcase_19 AC 199 ms
92,988 KB
testcase_20 AC 225 ms
94,720 KB
testcase_21 AC 236 ms
93,632 KB
testcase_22 AC 220 ms
94,800 KB
testcase_23 AC 225 ms
93,188 KB
testcase_24 AC 259 ms
103,384 KB
testcase_25 AC 235 ms
98,328 KB
testcase_26 AC 246 ms
98,276 KB
testcase_27 AC 237 ms
99,860 KB
testcase_28 AC 245 ms
98,896 KB
testcase_29 AC 254 ms
103,924 KB
testcase_30 AC 243 ms
99,512 KB
testcase_31 AC 243 ms
97,256 KB
testcase_32 AC 247 ms
97,912 KB
testcase_33 AC 248 ms
97,024 KB
testcase_34 AC 187 ms
101,140 KB
testcase_35 AC 190 ms
99,988 KB
testcase_36 AC 225 ms
102,128 KB
testcase_37 AC 217 ms
100,988 KB
testcase_38 AC 201 ms
93,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

N,M,A,B = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(M)]
E = [[] for _ in range(B - A + 2)]
N2 = B - A + 1
for i in range(M):
    l,r = LR[i]
    a = max(0,min(B-A+1,l-A))
    b = max(0,min(B-A+1,r-A+1))
    E[a].append((b))
    E[b].append((a))
#print(E)
q1 = {0}
q2 = set()
nvstd = [True] * (N2+1)
nvstd[0] = False
ans = 0
while q1:
    ans += 1
    while q1:
        frm = next(iter(q1))
        q1.remove(frm)
        for to in E[frm]:
            if to == N2:
                print(ans)
                sys.exit()

            if nvstd[to]:
                q2.add(to)
                nvstd[to] = False

    q1,q2 = q2,q1
    q2 = set()

print(-1)

0