結果

問題 No.1344 Typical Shortest Path Sum
ユーザー H3PO4H3PO4
提出日時 2021-01-16 13:17:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,803 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 78,500 KB
最終ジャッジ日時 2023-08-09 15:45:32
合計ジャッジ時間 10,069 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,803 ms
43,412 KB
testcase_01 AC 192 ms
42,948 KB
testcase_02 AC 196 ms
43,272 KB
testcase_03 AC 196 ms
43,256 KB
testcase_04 AC 198 ms
43,340 KB
testcase_05 AC 198 ms
42,920 KB
testcase_06 AC 202 ms
43,032 KB
testcase_07 AC 207 ms
43,360 KB
testcase_08 AC 197 ms
43,240 KB
testcase_09 AC 196 ms
43,392 KB
testcase_10 AC 194 ms
43,176 KB
testcase_11 AC 199 ms
42,936 KB
testcase_12 AC 201 ms
43,260 KB
testcase_13 AC 195 ms
42,980 KB
testcase_14 AC 200 ms
43,168 KB
testcase_15 AC 197 ms
43,116 KB
testcase_16 AC 200 ms
43,476 KB
testcase_17 AC 203 ms
43,220 KB
testcase_18 AC 201 ms
43,432 KB
testcase_19 AC 194 ms
43,068 KB
testcase_20 AC 197 ms
42,876 KB
testcase_21 AC 199 ms
43,028 KB
testcase_22 AC 197 ms
43,260 KB
testcase_23 AC 196 ms
43,216 KB
testcase_24 AC 201 ms
43,072 KB
testcase_25 AC 203 ms
43,232 KB
testcase_26 AC 201 ms
43,120 KB
testcase_27 AC 202 ms
42,980 KB
testcase_28 AC 206 ms
43,176 KB
testcase_29 AC 211 ms
43,044 KB
testcase_30 AC 202 ms
43,256 KB
testcase_31 AC 202 ms
43,364 KB
testcase_32 AC 200 ms
42,944 KB
testcase_33 AC 206 ms
43,060 KB
testcase_34 AC 200 ms
42,960 KB
testcase_35 AC 200 ms
43,248 KB
testcase_36 AC 198 ms
42,980 KB
testcase_37 AC 199 ms
43,168 KB
testcase_38 AC 201 ms
43,008 KB
testcase_39 AC 193 ms
43,076 KB
testcase_40 AC 196 ms
43,640 KB
testcase_41 AC 198 ms
43,684 KB
testcase_42 AC 197 ms
43,620 KB
testcase_43 AC 192 ms
43,496 KB
testcase_44 AC 189 ms
43,420 KB
testcase_45 AC 194 ms
43,404 KB
testcase_46 AC 194 ms
43,424 KB
testcase_47 AC 198 ms
43,460 KB
testcase_48 AC 198 ms
43,524 KB
testcase_49 AC 196 ms
43,460 KB
testcase_50 AC 194 ms
43,584 KB
testcase_51 AC 199 ms
43,520 KB
testcase_52 AC 201 ms
43,752 KB
testcase_53 AC 194 ms
43,664 KB
testcase_54 AC 195 ms
43,648 KB
testcase_55 AC 202 ms
43,408 KB
testcase_56 AC 202 ms
43,648 KB
testcase_57 AC 201 ms
43,616 KB
testcase_58 AC 197 ms
43,464 KB
testcase_59 AC 201 ms
43,628 KB
testcase_60 AC 205 ms
43,120 KB
testcase_61 AC 212 ms
43,176 KB
testcase_62 AC 205 ms
43,488 KB
testcase_63 AC 201 ms
43,312 KB
testcase_64 AC 200 ms
43,124 KB
testcase_65 AC 209 ms
43,468 KB
testcase_66 AC 202 ms
43,272 KB
testcase_67 AC 199 ms
43,328 KB
testcase_68 AC 190 ms
43,216 KB
testcase_69 AC 197 ms
43,292 KB
testcase_70 AC 197 ms
43,248 KB
testcase_71 AC 195 ms
43,260 KB
testcase_72 AC 192 ms
43,052 KB
testcase_73 AC 194 ms
43,172 KB
testcase_74 AC 197 ms
43,184 KB
testcase_75 AC 191 ms
43,444 KB
testcase_76 AC 196 ms
43,208 KB
testcase_77 AC 200 ms
43,504 KB
testcase_78 AC 203 ms
43,264 KB
testcase_79 AC 193 ms
78,500 KB
権限があれば一括ダウンロードができます

ソースコード

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