結果

問題 No.1995 CHIKA Road
ユーザー とりゐとりゐ
提出日時 2022-07-01 21:35:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,139 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 194,260 KB
最終ジャッジ日時 2024-05-04 15:48:07
合計ジャッジ時間 17,628 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
53,760 KB
testcase_01 AC 53 ms
54,144 KB
testcase_02 AC 47 ms
54,016 KB
testcase_03 AC 48 ms
54,144 KB
testcase_04 AC 49 ms
54,400 KB
testcase_05 AC 62 ms
62,848 KB
testcase_06 AC 198 ms
81,728 KB
testcase_07 AC 317 ms
93,788 KB
testcase_08 AC 70 ms
66,048 KB
testcase_09 AC 64 ms
63,616 KB
testcase_10 AC 339 ms
86,144 KB
testcase_11 AC 1,139 ms
194,260 KB
testcase_12 AC 429 ms
122,544 KB
testcase_13 AC 427 ms
111,452 KB
testcase_14 AC 446 ms
111,752 KB
testcase_15 AC 952 ms
174,960 KB
testcase_16 AC 221 ms
84,608 KB
testcase_17 AC 524 ms
117,904 KB
testcase_18 AC 812 ms
145,368 KB
testcase_19 AC 799 ms
145,664 KB
testcase_20 AC 480 ms
114,564 KB
testcase_21 AC 445 ms
109,420 KB
testcase_22 AC 758 ms
139,708 KB
testcase_23 AC 311 ms
93,748 KB
testcase_24 AC 674 ms
131,764 KB
testcase_25 AC 250 ms
86,912 KB
testcase_26 AC 366 ms
99,620 KB
testcase_27 AC 646 ms
129,568 KB
testcase_28 AC 445 ms
109,312 KB
testcase_29 AC 763 ms
144,836 KB
testcase_30 AC 232 ms
85,632 KB
testcase_31 AC 191 ms
80,776 KB
testcase_32 AC 261 ms
88,192 KB
testcase_33 AC 639 ms
128,828 KB
testcase_34 AC 193 ms
81,976 KB
testcase_35 AC 342 ms
95,844 KB
testcase_36 AC 401 ms
104,228 KB
testcase_37 AC 721 ms
135,764 KB
testcase_38 AC 566 ms
118,800 KB
testcase_39 AC 211 ms
80,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
INF=10**18
def dijkstra():
  dist=defaultdict(lambda:INF)
  hq=[(0,1)]
  dist[1]=0
  seen=set()
  while hq:
    w,v=heappop(hq)
    if dist[v]<w:
      continue
    seen.add(v)
    for to,cost in edge[v]:
      if to not in seen and dist[v]+cost<dist[to]:
        dist[to]=dist[v]+cost
        heappush(hq,(dist[to],to))
  return dist

from collections import defaultdict
edge=defaultdict(list)
n,m=map(int,input().split())
town=set([1,n])
for _ in range(m):
  a,b=map(int,input().split())
  town.add(a)
  town.add(b)
  edge[a].append((b,2*b-2*a-1))

town=sorted(list(town))
k=len(town)
for i in range(k-1):
  edge[town[i]].append((town[i+1],2*(town[i+1]-town[i])))
#print(edge)
d=dijkstra()
print(d[n])
0