結果

問題 No.1344 Typical Shortest Path Sum
ユーザー H3PO4H3PO4
提出日時 2021-01-16 13:17:29
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,744 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 101,984 KB
最終ジャッジ日時 2024-11-15 11:55:23
合計ジャッジ時間 82,963 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 77
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

import numpy as np

from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N, M = map(int, input().split())
length, frm, to = [], [], []

MAX = 10 ** 13

edges_dict = defaultdict(lambda: MAX)
for _ in range(M):
    s, t, d = map(int, input().split())
    s -= 1
    t -= 1
    edges_dict[(s, t)] = min(edges_dict[(s, t)], d)

for (s, t), d in edges_dict.items():
    length.append(d)
    frm.append(s)
    to.append(t)

matr = csr_matrix((length, (frm, to)), shape=(N, N))
way = floyd_warshall(matr)
way = np.where(np.isinf(way), 0, way.astype(np.int64))
print(*way.sum(axis=1), sep='\n')
0