結果

問題 No.1244 Black Segment
ユーザー rin204
提出日時 2022-07-06 06:53:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 661 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 81,928 KB
実行使用メモリ 88,276 KB
最終ジャッジ日時 2024-12-18 00:45:16
合計ジャッジ時間 7,344 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n, m, a, b = map(int, input().split())
n = b - a + 2
edges = [[] for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    if l <= a and b <= r:
        print(1)
        exit()
    elif r <= a or b <= l:
        pass
    else:
        l = max(l, a) - a
        r = min(r, b) - a + 1
        edges[l].append(r)
        edges[r].append(l)
        
queue = deque()
queue.append(0)
dist = [-1] * n
dist[0] = 0
while queue:
    pos = queue.popleft()
    for npos in edges[pos]:
        if dist[npos] != -1:
            continue
        dist[npos] = dist[pos] + 1
        queue.append(npos)
print(dist[-1])
        
0