結果

問題 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  
実行時間 949 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 118,536 KB
最終ジャッジ日時 2024-04-27 10:35:01
合計ジャッジ時間 70,323 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 869 ms
56,624 KB
testcase_01 AC 820 ms
56,368 KB
testcase_02 AC 811 ms
56,236 KB
testcase_03 AC 811 ms
56,748 KB
testcase_04 AC 858 ms
56,372 KB
testcase_05 AC 814 ms
56,240 KB
testcase_06 AC 810 ms
56,236 KB
testcase_07 AC 811 ms
56,632 KB
testcase_08 AC 812 ms
56,492 KB
testcase_09 AC 822 ms
56,508 KB
testcase_10 AC 819 ms
56,496 KB
testcase_11 AC 807 ms
56,240 KB
testcase_12 AC 816 ms
56,624 KB
testcase_13 AC 828 ms
56,240 KB
testcase_14 AC 815 ms
56,624 KB
testcase_15 AC 842 ms
56,240 KB
testcase_16 AC 818 ms
56,628 KB
testcase_17 AC 815 ms
56,760 KB
testcase_18 AC 811 ms
56,632 KB
testcase_19 AC 811 ms
56,620 KB
testcase_20 AC 813 ms
56,368 KB
testcase_21 AC 822 ms
56,116 KB
testcase_22 AC 825 ms
56,368 KB
testcase_23 AC 820 ms
56,624 KB
testcase_24 AC 820 ms
56,112 KB
testcase_25 AC 806 ms
56,364 KB
testcase_26 AC 818 ms
56,492 KB
testcase_27 AC 809 ms
56,244 KB
testcase_28 AC 801 ms
56,876 KB
testcase_29 AC 812 ms
56,212 KB
testcase_30 AC 802 ms
56,496 KB
testcase_31 AC 814 ms
56,624 KB
testcase_32 AC 826 ms
56,116 KB
testcase_33 AC 812 ms
56,244 KB
testcase_34 AC 803 ms
56,364 KB
testcase_35 AC 795 ms
56,500 KB
testcase_36 AC 797 ms
56,236 KB
testcase_37 AC 804 ms
56,244 KB
testcase_38 AC 801 ms
56,240 KB
testcase_39 AC 812 ms
56,364 KB
testcase_40 AC 816 ms
56,500 KB
testcase_41 AC 807 ms
56,756 KB
testcase_42 AC 815 ms
56,628 KB
testcase_43 AC 804 ms
56,500 KB
testcase_44 AC 806 ms
56,620 KB
testcase_45 AC 809 ms
56,752 KB
testcase_46 AC 876 ms
56,632 KB
testcase_47 AC 850 ms
56,620 KB
testcase_48 AC 808 ms
56,620 KB
testcase_49 AC 794 ms
56,496 KB
testcase_50 AC 799 ms
56,752 KB
testcase_51 AC 813 ms
56,636 KB
testcase_52 AC 811 ms
56,496 KB
testcase_53 AC 804 ms
56,620 KB
testcase_54 AC 803 ms
56,632 KB
testcase_55 AC 792 ms
56,628 KB
testcase_56 AC 812 ms
56,404 KB
testcase_57 AC 800 ms
56,496 KB
testcase_58 AC 817 ms
56,496 KB
testcase_59 AC 815 ms
56,748 KB
testcase_60 AC 806 ms
56,272 KB
testcase_61 AC 806 ms
56,372 KB
testcase_62 AC 805 ms
56,116 KB
testcase_63 AC 824 ms
56,240 KB
testcase_64 AC 800 ms
56,492 KB
testcase_65 AC 809 ms
56,240 KB
testcase_66 AC 822 ms
56,372 KB
testcase_67 AC 810 ms
56,376 KB
testcase_68 AC 820 ms
56,116 KB
testcase_69 AC 815 ms
56,496 KB
testcase_70 AC 820 ms
56,880 KB
testcase_71 AC 820 ms
56,504 KB
testcase_72 AC 806 ms
56,244 KB
testcase_73 AC 949 ms
56,236 KB
testcase_74 AC 802 ms
56,624 KB
testcase_75 AC 798 ms
56,504 KB
testcase_76 AC 803 ms
56,760 KB
testcase_77 AC 794 ms
56,756 KB
testcase_78 AC 799 ms
56,384 KB
testcase_79 AC 802 ms
118,536 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