結果

問題 No.1244 Black Segment
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-24 16:54:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 549 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 81,888 KB
実行使用メモリ 107,160 KB
最終ジャッジ日時 2023-10-24 22:38:47
合計ジャッジ時間 9,893 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,560 KB
testcase_01 AC 34 ms
53,560 KB
testcase_02 AC 34 ms
53,560 KB
testcase_03 AC 34 ms
53,560 KB
testcase_04 AC 34 ms
53,560 KB
testcase_05 AC 34 ms
53,560 KB
testcase_06 AC 34 ms
53,560 KB
testcase_07 AC 37 ms
53,560 KB
testcase_08 AC 35 ms
53,560 KB
testcase_09 AC 37 ms
53,560 KB
testcase_10 AC 34 ms
53,560 KB
testcase_11 AC 34 ms
53,560 KB
testcase_12 AC 33 ms
53,560 KB
testcase_13 AC 112 ms
77,800 KB
testcase_14 AC 195 ms
89,480 KB
testcase_15 AC 114 ms
77,756 KB
testcase_16 AC 184 ms
89,472 KB
testcase_17 AC 104 ms
77,240 KB
testcase_18 AC 262 ms
93,404 KB
testcase_19 AC 450 ms
102,092 KB
testcase_20 AC 411 ms
101,756 KB
testcase_21 AC 233 ms
98,940 KB
testcase_22 AC 391 ms
101,332 KB
testcase_23 AC 389 ms
101,236 KB
testcase_24 AC 324 ms
99,808 KB
testcase_25 AC 334 ms
101,396 KB
testcase_26 AC 278 ms
98,148 KB
testcase_27 AC 176 ms
99,004 KB
testcase_28 AC 365 ms
102,196 KB
testcase_29 AC 272 ms
99,428 KB
testcase_30 AC 319 ms
100,276 KB
testcase_31 AC 261 ms
99,780 KB
testcase_32 AC 263 ms
99,932 KB
testcase_33 AC 266 ms
99,436 KB
testcase_34 AC 281 ms
100,312 KB
testcase_35 AC 308 ms
105,480 KB
testcase_36 AC 282 ms
103,344 KB
testcase_37 AC 419 ms
107,160 KB
testcase_38 AC 287 ms
100,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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