結果

問題 No.1344 Typical Shortest Path Sum
ユーザー ryusukeryusuke
提出日時 2022-05-06 19:17:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 2,248 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 77,756 KB
最終ジャッジ日時 2023-09-19 08:27:46
合計ジャッジ時間 11,407 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,256 KB
testcase_01 AC 76 ms
71,164 KB
testcase_02 AC 75 ms
71,380 KB
testcase_03 AC 97 ms
76,444 KB
testcase_04 AC 86 ms
76,144 KB
testcase_05 AC 74 ms
71,404 KB
testcase_06 AC 74 ms
71,112 KB
testcase_07 AC 74 ms
71,492 KB
testcase_08 AC 74 ms
71,396 KB
testcase_09 AC 75 ms
71,244 KB
testcase_10 AC 75 ms
71,112 KB
testcase_11 AC 76 ms
71,204 KB
testcase_12 AC 76 ms
71,060 KB
testcase_13 AC 76 ms
71,464 KB
testcase_14 AC 75 ms
71,344 KB
testcase_15 AC 76 ms
71,180 KB
testcase_16 AC 117 ms
77,500 KB
testcase_17 AC 74 ms
71,396 KB
testcase_18 AC 76 ms
71,168 KB
testcase_19 AC 76 ms
71,328 KB
testcase_20 AC 75 ms
71,284 KB
testcase_21 AC 75 ms
71,452 KB
testcase_22 AC 75 ms
71,388 KB
testcase_23 AC 76 ms
71,080 KB
testcase_24 AC 75 ms
71,416 KB
testcase_25 AC 76 ms
71,228 KB
testcase_26 AC 74 ms
71,136 KB
testcase_27 AC 73 ms
71,404 KB
testcase_28 AC 76 ms
71,244 KB
testcase_29 AC 76 ms
71,120 KB
testcase_30 AC 74 ms
71,400 KB
testcase_31 AC 75 ms
71,172 KB
testcase_32 AC 76 ms
71,236 KB
testcase_33 AC 75 ms
71,460 KB
testcase_34 AC 75 ms
71,048 KB
testcase_35 AC 75 ms
71,152 KB
testcase_36 AC 77 ms
71,392 KB
testcase_37 AC 77 ms
71,364 KB
testcase_38 AC 77 ms
71,284 KB
testcase_39 AC 78 ms
71,436 KB
testcase_40 AC 140 ms
77,264 KB
testcase_41 AC 146 ms
77,472 KB
testcase_42 AC 140 ms
77,120 KB
testcase_43 AC 135 ms
77,440 KB
testcase_44 AC 137 ms
77,540 KB
testcase_45 AC 137 ms
77,368 KB
testcase_46 AC 139 ms
77,324 KB
testcase_47 AC 147 ms
77,428 KB
testcase_48 AC 143 ms
77,664 KB
testcase_49 AC 131 ms
77,268 KB
testcase_50 AC 133 ms
77,508 KB
testcase_51 AC 143 ms
77,352 KB
testcase_52 AC 133 ms
77,612 KB
testcase_53 AC 146 ms
77,432 KB
testcase_54 AC 133 ms
77,388 KB
testcase_55 AC 142 ms
77,756 KB
testcase_56 AC 138 ms
77,572 KB
testcase_57 AC 136 ms
77,360 KB
testcase_58 AC 143 ms
77,356 KB
testcase_59 AC 137 ms
77,724 KB
testcase_60 AC 86 ms
75,728 KB
testcase_61 AC 77 ms
71,180 KB
testcase_62 AC 111 ms
77,096 KB
testcase_63 AC 91 ms
76,112 KB
testcase_64 AC 94 ms
76,184 KB
testcase_65 AC 119 ms
77,448 KB
testcase_66 AC 110 ms
76,992 KB
testcase_67 AC 109 ms
76,976 KB
testcase_68 AC 89 ms
76,192 KB
testcase_69 AC 93 ms
76,164 KB
testcase_70 AC 95 ms
75,960 KB
testcase_71 AC 78 ms
71,400 KB
testcase_72 AC 78 ms
71,248 KB
testcase_73 AC 79 ms
71,100 KB
testcase_74 AC 79 ms
71,284 KB
testcase_75 AC 78 ms
71,116 KB
testcase_76 AC 77 ms
71,328 KB
testcase_77 AC 79 ms
71,116 KB
testcase_78 AC 78 ms
71,508 KB
testcase_79 AC 93 ms
76,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# warshall_floyd法
def warshall_floyd() -> list:
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    return dist

INF = float('inf')
n, m = map(int,input().split()) # 頂点数・辺の数

dist = [[INF] * n for _ in range(n)] # 隣接行列の初期化

# 自分自身へのコストは 0
for i in range(n):
    dist[i][i] = 0

# 与えられた距離の初期化
for i in range(m):
    x, y, r = map(int,input().split())
    dist[x - 1][y - 1] = min(dist[x - 1][y - 1], r)

ans = warshall_floyd()

for i in range(n):
    num = 0
    for j in range(n):
        if i != j and ans[i][j] < INF:
            num += ans[i][j]
    print(num)
0