結果

問題 No.807 umg tours
ユーザー takakintakakin
提出日時 2020-05-27 22:25:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,168 ms / 4,000 ms
コード長 975 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 100,876 KB
最終ジャッジ日時 2023-08-15 12:53:07
合計ジャッジ時間 21,590 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,340 KB
testcase_01 AC 17 ms
8,424 KB
testcase_02 AC 18 ms
8,496 KB
testcase_03 AC 18 ms
8,540 KB
testcase_04 AC 15 ms
8,372 KB
testcase_05 AC 16 ms
8,460 KB
testcase_06 AC 17 ms
8,512 KB
testcase_07 AC 17 ms
8,472 KB
testcase_08 AC 14 ms
8,308 KB
testcase_09 AC 15 ms
8,352 KB
testcase_10 AC 15 ms
8,460 KB
testcase_11 AC 1,502 ms
76,584 KB
testcase_12 AC 1,110 ms
61,316 KB
testcase_13 AC 1,659 ms
81,008 KB
testcase_14 AC 658 ms
40,848 KB
testcase_15 AC 486 ms
33,932 KB
testcase_16 AC 1,746 ms
83,588 KB
testcase_17 AC 2,158 ms
99,168 KB
testcase_18 AC 2,093 ms
98,216 KB
testcase_19 AC 2,047 ms
95,424 KB
testcase_20 AC 968 ms
58,096 KB
testcase_21 AC 1,016 ms
60,044 KB
testcase_22 AC 369 ms
30,728 KB
testcase_23 AC 294 ms
25,756 KB
testcase_24 AC 1,078 ms
76,104 KB
testcase_25 AC 2,168 ms
100,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()

n,m=map(int,input().split())
nn=2*n
edge=[[] for i in range(nn)]
for i in range(m):
  a,b,c=map(int,input().split())
  edge[a-1].append(c*10**6+b-1)
  edge[b-1].append(c*10**6+a-1)
  edge[a-1].append(b-1+n)
  edge[b-1].append(a-1+n)
  edge[a-1+n].append(c*10**6+b-1+n)
  edge[b-1+n].append(c*10**6+a-1+n)

import heapq
def dijkstra_heap(s):
  d=[float("inf")]*nn
  used=[True]*nn
  d[s]=0
  used[s]=False
  edgelist=[]
  for e in edge[s]:
    heapq.heappush(edgelist,e)
  while edgelist:
    minedge=heapq.heappop(edgelist)
    minedge_cost=minedge//(10**6)
    minedge_v=minedge%(10**6)
    if not used[minedge_v]:
      continue
    d[minedge_v] = minedge_cost
    used[minedge_v] = False
    for e in edge[minedge_v]:
      e_cost=e//(10**6)
      e_v=e%(10**6)
      if used[e_v]:
        heapq.heappush(edgelist,e+minedge_cost*10**6)
  return d
D=dijkstra_heap(0)
print(0)
for i in range(1,n):
  print(D[i]+D[n+i])
0