結果

問題 No.1244 Black Segment
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-24 16:59:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 306 ms / 2,000 ms
コード長 523 bytes
コンパイル時間 1,439 ms
コンパイル使用メモリ 81,632 KB
実行使用メモリ 116,100 KB
最終ジャッジ日時 2023-10-24 22:42:45
合計ジャッジ時間 9,257 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,552 KB
testcase_01 AC 42 ms
55,552 KB
testcase_02 AC 41 ms
55,552 KB
testcase_03 AC 41 ms
55,552 KB
testcase_04 AC 43 ms
55,552 KB
testcase_05 AC 42 ms
55,552 KB
testcase_06 AC 42 ms
55,552 KB
testcase_07 AC 42 ms
55,552 KB
testcase_08 AC 42 ms
55,552 KB
testcase_09 AC 42 ms
55,552 KB
testcase_10 AC 41 ms
55,552 KB
testcase_11 AC 42 ms
55,552 KB
testcase_12 AC 42 ms
55,552 KB
testcase_13 AC 100 ms
77,176 KB
testcase_14 AC 199 ms
86,892 KB
testcase_15 AC 102 ms
77,140 KB
testcase_16 AC 186 ms
86,548 KB
testcase_17 AC 87 ms
76,852 KB
testcase_18 AC 215 ms
104,268 KB
testcase_19 AC 246 ms
97,800 KB
testcase_20 AC 258 ms
104,160 KB
testcase_21 AC 207 ms
93,272 KB
testcase_22 AC 265 ms
104,160 KB
testcase_23 AC 306 ms
107,620 KB
testcase_24 AC 275 ms
108,708 KB
testcase_25 AC 252 ms
104,188 KB
testcase_26 AC 271 ms
107,976 KB
testcase_27 AC 284 ms
116,100 KB
testcase_28 AC 268 ms
105,088 KB
testcase_29 AC 274 ms
108,980 KB
testcase_30 AC 256 ms
103,416 KB
testcase_31 AC 292 ms
105,252 KB
testcase_32 AC 287 ms
105,332 KB
testcase_33 AC 281 ms
105,056 KB
testcase_34 AC 166 ms
88,668 KB
testcase_35 AC 171 ms
89,840 KB
testcase_36 AC 227 ms
105,536 KB
testcase_37 AC 277 ms
111,880 KB
testcase_38 AC 254 ms
104,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m,a,b=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(m)]
g=[set() for _ in range(n+2)]
for l,r in lr:
  r+=1
  l=max(l,a)
  l=min(b+1,l)
  r=max(r,a)
  r=min(b+1,r)
  g[l].add(r)
  g[r].add(l)
inf=float('inf')
seen=[inf]*(n+2)
ans=inf
from collections import deque
todo=deque([a])
seen[a]=0
while todo:
  v=todo.popleft()
  if v>b:
    ans=min(ans,seen[v])
    continue
  nc=seen[v]+1
  for nv in g[v]:
    if seen[nv]>nc:
      seen[nv]=nc
      todo.append(nv)
print(-1 if ans==inf else ans)
0