結果

問題 No.1995 CHIKA Road
ユーザー titan23titan23
提出日時 2022-07-01 23:00:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 968 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 181,124 KB
最終ジャッジ日時 2023-08-17 10:38:04
合計ジャッジ時間 15,277 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,580 KB
testcase_01 AC 90 ms
71,664 KB
testcase_02 AC 85 ms
71,644 KB
testcase_03 AC 87 ms
71,828 KB
testcase_04 AC 89 ms
71,656 KB
testcase_05 WA -
testcase_06 AC 238 ms
85,024 KB
testcase_07 AC 300 ms
101,636 KB
testcase_08 AC 104 ms
77,000 KB
testcase_09 AC 100 ms
76,476 KB
testcase_10 AC 297 ms
92,420 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 222 ms
89,252 KB
testcase_17 AC 469 ms
126,092 KB
testcase_18 AC 676 ms
150,752 KB
testcase_19 AC 691 ms
151,624 KB
testcase_20 AC 436 ms
120,560 KB
testcase_21 AC 412 ms
116,696 KB
testcase_22 AC 662 ms
147,196 KB
testcase_23 AC 296 ms
101,476 KB
testcase_24 AC 592 ms
138,748 KB
testcase_25 AC 238 ms
89,900 KB
testcase_26 AC 345 ms
108,452 KB
testcase_27 AC 572 ms
137,740 KB
testcase_28 AC 409 ms
116,352 KB
testcase_29 AC 673 ms
149,868 KB
testcase_30 AC 231 ms
89,928 KB
testcase_31 AC 212 ms
83,692 KB
testcase_32 AC 260 ms
94,556 KB
testcase_33 AC 564 ms
136,300 KB
testcase_34 AC 216 ms
84,844 KB
testcase_35 AC 324 ms
104,532 KB
testcase_36 AC 358 ms
108,564 KB
testcase_37 AC 629 ms
145,092 KB
testcase_38 AC 486 ms
124,832 KB
testcase_39 AC 195 ms
83,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict
from heapq import heapify, heappush, heappop
input = lambda: sys.stdin.readline().rstrip()
inf = float('inf')

def dijkstra(G: list, s: int) -> list:
  "Return dist from s. / O(|E|log|V|)"
  dist = defaultdict(lambda: inf)
  dist[s] = 0
  hq = [(0, s)]
  while hq:
    d, v = heappop(hq)
    if dist[v] < d:
      continue
    for x,c in G[v]:
      if dist[x] > d + c:
        dist[x] = d + c
        heappush(hq, (d+c, x))
  return dist

#  -----------------------  #

n, m = map(int, input().split())
G = defaultdict(list)
st = defaultdict(set)
L = set()

for _ in range(m):
  a, b = map(int, input().split())
  G[a-1].append((b-1, 2*b-2*a-1))
  st[a-1].add(b-1)
  L.add(a-1)
  L.add(b-1)
if n-1 not in L:
  L.add(n-1)

L = sorted(list(L))

for i in range(len(L)-1):
  now, nxt = L[i], L[i+1]
  dist = (L[i+1] - L[i]) * 2
  if nxt not in st[now]:
    G[now].append((nxt, dist))

dist = dijkstra(G, 0)
print(dist[n-1])
0