結果

問題 No.1244 Black Segment
ユーザー NoneNone
提出日時 2021-05-06 07:03:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 298 ms / 2,000 ms
コード長 849 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 87,368 KB
実行使用メモリ 92,456 KB
最終ジャッジ日時 2023-10-12 00:15:17
合計ジャッジ時間 12,293 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
71,616 KB
testcase_01 AC 100 ms
71,740 KB
testcase_02 AC 99 ms
71,900 KB
testcase_03 AC 99 ms
71,928 KB
testcase_04 AC 100 ms
71,788 KB
testcase_05 AC 99 ms
71,892 KB
testcase_06 AC 100 ms
71,676 KB
testcase_07 AC 104 ms
71,684 KB
testcase_08 AC 101 ms
71,800 KB
testcase_09 AC 100 ms
71,468 KB
testcase_10 AC 99 ms
71,468 KB
testcase_11 AC 101 ms
71,784 KB
testcase_12 AC 97 ms
71,868 KB
testcase_13 AC 140 ms
78,208 KB
testcase_14 AC 213 ms
81,416 KB
testcase_15 AC 142 ms
78,220 KB
testcase_16 AC 201 ms
80,348 KB
testcase_17 AC 138 ms
78,388 KB
testcase_18 AC 227 ms
85,600 KB
testcase_19 AC 283 ms
88,736 KB
testcase_20 AC 275 ms
87,860 KB
testcase_21 AC 256 ms
87,388 KB
testcase_22 AC 276 ms
88,064 KB
testcase_23 AC 279 ms
87,992 KB
testcase_24 AC 270 ms
89,240 KB
testcase_25 AC 260 ms
88,492 KB
testcase_26 AC 271 ms
88,072 KB
testcase_27 AC 274 ms
90,312 KB
testcase_28 AC 295 ms
90,624 KB
testcase_29 AC 283 ms
89,360 KB
testcase_30 AC 267 ms
87,896 KB
testcase_31 AC 288 ms
89,388 KB
testcase_32 AC 298 ms
89,908 KB
testcase_33 AC 285 ms
89,368 KB
testcase_34 AC 201 ms
83,612 KB
testcase_35 AC 213 ms
87,272 KB
testcase_36 AC 251 ms
88,840 KB
testcase_37 AC 279 ms
92,456 KB
testcase_38 AC 291 ms
90,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def bfs(starts):
    dist=[INF]*(N+1)
    next_set=deque()
    for start in starts:
        next_set.append((start,0))
        dist[start]=0
    while next_set:
        p,t=next_set.popleft()
        for q in edges[p]:
            if dist[q]!=INF:
                continue
            dist[q]=t+1
            next_set.append((q,t+1))
    return dist

##############################################

N,M,A,B=map(int, input().split())
A-=1
B-=1
INF=10**18
res=INF
starts=[]
edges=[[] for _ in range(N+1)]
for _ in range(M):
    l,r=map(int, input().split())
    l-=1
    r-=1
    if l<=A:
        starts.append(l)
        edges[l].append(r+1)
    elif A<=l<=B:
        edges[l].append(r+1)
        edges[r+1].append(l)

dist=bfs(starts)

for i in range(B+1,N+1):
    res=min(dist[i],res)


print(res if res!=INF else -1)
0