結果

問題 No.1344 Typical Shortest Path Sum
ユーザー GER_chenGER_chen
提出日時 2021-01-26 12:39:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 817 bytes
コンパイル時間 1,277 ms
コンパイル使用メモリ 86,648 KB
実行使用メモリ 78,200 KB
最終ジャッジ日時 2023-09-05 17:00:34
合計ジャッジ時間 10,614 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,148 KB
testcase_01 AC 77 ms
71,312 KB
testcase_02 AC 73 ms
71,164 KB
testcase_03 AC 102 ms
76,340 KB
testcase_04 AC 84 ms
76,008 KB
testcase_05 AC 72 ms
71,116 KB
testcase_06 AC 72 ms
71,188 KB
testcase_07 AC 74 ms
71,356 KB
testcase_08 AC 73 ms
70,968 KB
testcase_09 AC 76 ms
71,192 KB
testcase_10 AC 73 ms
71,316 KB
testcase_11 AC 73 ms
71,148 KB
testcase_12 AC 73 ms
71,172 KB
testcase_13 AC 72 ms
71,172 KB
testcase_14 AC 74 ms
71,412 KB
testcase_15 AC 72 ms
71,000 KB
testcase_16 AC 110 ms
77,704 KB
testcase_17 AC 73 ms
71,196 KB
testcase_18 AC 74 ms
71,112 KB
testcase_19 AC 72 ms
71,348 KB
testcase_20 AC 73 ms
70,968 KB
testcase_21 AC 75 ms
71,260 KB
testcase_22 AC 73 ms
71,116 KB
testcase_23 AC 76 ms
71,180 KB
testcase_24 AC 74 ms
71,188 KB
testcase_25 AC 75 ms
71,168 KB
testcase_26 AC 73 ms
71,180 KB
testcase_27 AC 74 ms
71,144 KB
testcase_28 AC 72 ms
71,160 KB
testcase_29 AC 72 ms
71,172 KB
testcase_30 AC 72 ms
71,016 KB
testcase_31 AC 74 ms
71,396 KB
testcase_32 AC 73 ms
71,292 KB
testcase_33 AC 75 ms
71,324 KB
testcase_34 AC 74 ms
71,216 KB
testcase_35 AC 74 ms
71,348 KB
testcase_36 AC 73 ms
71,288 KB
testcase_37 AC 73 ms
71,420 KB
testcase_38 AC 72 ms
71,168 KB
testcase_39 AC 72 ms
71,380 KB
testcase_40 AC 128 ms
77,712 KB
testcase_41 AC 140 ms
77,896 KB
testcase_42 AC 128 ms
77,332 KB
testcase_43 AC 124 ms
77,616 KB
testcase_44 AC 126 ms
77,348 KB
testcase_45 AC 128 ms
77,332 KB
testcase_46 AC 130 ms
77,408 KB
testcase_47 AC 134 ms
77,464 KB
testcase_48 AC 134 ms
77,452 KB
testcase_49 AC 124 ms
77,320 KB
testcase_50 AC 127 ms
77,540 KB
testcase_51 AC 132 ms
77,488 KB
testcase_52 AC 126 ms
77,688 KB
testcase_53 AC 135 ms
77,504 KB
testcase_54 AC 124 ms
77,308 KB
testcase_55 AC 131 ms
77,692 KB
testcase_56 AC 129 ms
77,756 KB
testcase_57 AC 125 ms
77,704 KB
testcase_58 AC 134 ms
77,268 KB
testcase_59 AC 131 ms
77,836 KB
testcase_60 AC 81 ms
75,580 KB
testcase_61 AC 74 ms
71,036 KB
testcase_62 AC 115 ms
77,968 KB
testcase_63 AC 87 ms
76,456 KB
testcase_64 AC 89 ms
76,172 KB
testcase_65 AC 115 ms
77,908 KB
testcase_66 AC 115 ms
78,200 KB
testcase_67 AC 115 ms
77,944 KB
testcase_68 AC 88 ms
76,116 KB
testcase_69 AC 87 ms
76,112 KB
testcase_70 AC 85 ms
75,632 KB
testcase_71 AC 75 ms
71,308 KB
testcase_72 AC 75 ms
71,312 KB
testcase_73 AC 75 ms
71,420 KB
testcase_74 AC 74 ms
71,176 KB
testcase_75 AC 75 ms
71,176 KB
testcase_76 AC 74 ms
71,280 KB
testcase_77 AC 75 ms
71,072 KB
testcase_78 AC 74 ms
71,428 KB
testcase_79 AC 90 ms
76,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def floyd_warshall(n, Edges):
    """
    n: number of vertices
    Edges: set of edges
    """
    sp = [[float('inf')]*n for _ in range(n)]
    for init, end, weight in Edges:
        if sp[init][end] > weight:
            sp[init][end] = weight  #no multi edge
    for i in range(n):
        sp[i][i] = 0
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if sp[j][k] > sp[j][i]+sp[i][k]:
                    sp[j][k] = sp[j][i]+sp[i][k]
    return sp

N, M = map(int, input().split())  #N頂点、M辺

#辺集合
Edges = set()
for _ in range(M):
    s, t, d = map(int, input().split())
    Edges.add((s-1, t-1, d))

#到達不可能な場合0にする設定
sp = floyd_warshall(N, Edges)
for i in range(N):
    print(sum(l if l < float('inf') else 0 for l in sp[i]))
0