結果
| 問題 |
No.1344 Typical Shortest Path Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-24 13:49:20 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 647 bytes |
| コンパイル時間 | 117 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-12-14 08:56:31 |
| 合計ジャッジ時間 | 5,259 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 WA * 25 |
ソースコード
import heapq
n,m=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
s,t,d=map(int,input().split())
g[s-1].append((t-1,d))
def dijkstra(s):
dst=[0]*n
confirmed=[False]*n
q=[]
heapq.heappush(q,(0,s))
while q:
now_dst,now_place=heapq.heappop(q)
if confirmed[now_place]:
continue
dst[now_place]=now_dst
confirmed[now_place]=True
for to_place,cost in g[now_place]:
if not confirmed[to_place]:
to_dst=now_dst+cost
heapq.heappush(q,(to_dst,to_place))
return sum(dst)
for i in range(n):
print(dijkstra(i))