結果

問題 No.1244 Black Segment
ユーザー AEn
提出日時 2023-03-28 15:32:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 505 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,040 KB
実行使用メモリ 88,264 KB
最終ジャッジ日時 2024-09-20 05:18:08
合計ジャッジ時間 6,848 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque


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

G = [list() for _ in range(N+2)]
for i in range(M):
    l,r = map(int, input().split())
    if (l<=A and r<=A) or (l>=B and r>=B):continue
    if l<=A:
        l = A
    if r>=B:
        r = B
    G[l].append(r+1)
    G[r+1].append(l)

dis = [-1]*(N+2)
dis[A] = 0
d = deque()
d.append(A)
while d:
    v = d.popleft()
    for nex in G[v]:
        if dis[nex]==-1:
            dis[nex] = dis[v]+1
            d.append(nex)
print(dis[B+1])
0