結果

問題 No.1244 Black Segment
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-24 16:46:45
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 700 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 81,584 KB
実行使用メモリ 104,456 KB
最終ジャッジ日時 2023-10-24 22:30:34
合計ジャッジ時間 13,322 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,392 KB
testcase_01 AC 39 ms
53,392 KB
testcase_02 AC 38 ms
53,392 KB
testcase_03 AC 39 ms
53,392 KB
testcase_04 AC 39 ms
53,392 KB
testcase_05 AC 38 ms
53,392 KB
testcase_06 AC 39 ms
53,392 KB
testcase_07 AC 39 ms
53,392 KB
testcase_08 AC 38 ms
53,392 KB
testcase_09 AC 38 ms
53,392 KB
testcase_10 AC 38 ms
53,392 KB
testcase_11 AC 38 ms
53,392 KB
testcase_12 AC 38 ms
53,392 KB
testcase_13 AC 142 ms
77,028 KB
testcase_14 AC 216 ms
89,080 KB
testcase_15 AC 114 ms
77,576 KB
testcase_16 AC 203 ms
89,052 KB
testcase_17 AC 82 ms
76,756 KB
testcase_18 AC 255 ms
92,960 KB
testcase_19 AC 641 ms
98,204 KB
testcase_20 AC 336 ms
98,788 KB
testcase_21 AC 176 ms
95,508 KB
testcase_22 AC 444 ms
99,828 KB
testcase_23 AC 607 ms
104,456 KB
testcase_24 AC 442 ms
99,636 KB
testcase_25 AC 438 ms
99,608 KB
testcase_26 AC 397 ms
99,312 KB
testcase_27 AC 213 ms
100,168 KB
testcase_28 AC 536 ms
99,640 KB
testcase_29 AC 363 ms
100,168 KB
testcase_30 AC 412 ms
99,640 KB
testcase_31 AC 219 ms
99,376 KB
testcase_32 AC 222 ms
99,640 KB
testcase_33 AC 225 ms
99,616 KB
testcase_34 AC 204 ms
99,376 KB
testcase_35 AC 167 ms
88,568 KB
testcase_36 AC 201 ms
100,432 KB
testcase_37 TLE -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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
todo0=[]
for v0 in range(a+1):
  for nv in g[v0]:
    if nv>a:
      if seen[nv]==inf:
        todo0.append(nv)
        seen[nv]=1
seen=[inf]*(n+2)
while todo0:
  v0=todo0.pop()
  todo=[[1,v0]]
  seen[v0]=1
  while todo:
    c,v=heappop(todo)
    if v>b:
      ans=min(ans,c)
      continue
    if seen[v]!=c:continue
    for nv in g[v]:
      if a<nv and seen[nv]>c+1:
        seen[nv]=c+1
        heappush(todo,[c+1,nv])
print(-1 if ans==inf else ans)
0