結果

問題 No.1244 Black Segment
ユーザー Shinya Fujita
提出日時 2024-10-11 16:08:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 476 bytes
コンパイル時間 455 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 89,984 KB
最終ジャッジ日時 2024-10-11 16:08:53
合計ジャッジ時間 8,952 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 9 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n,m,a,b=map(int,input().split())
g=[[] for _ in range(n+2)]
q=deque([])
for _ in range(m):
  l,r=map(int,input().split())
  g[l].append(r+1)
  g[r+1].append(l)
  if l<=a:
    q.append((0,l))

d=[-1]*(n+2)
while q:
  dd,i=q.popleft()
  if 0<=d[i]<=dd:
    continue
  d[i]=dd
  for j in g[i]:
    if d[j]==-1:
      q.append((j,dd+1))

ans=-1
for i in range(b+1,n+2):
  if d[i]>=-1:
    if ans==-1:
      ans=d[i]
    ans=min(ans,d[i])

print(ans)
0