結果

問題 No.1344 Typical Shortest Path Sum
ユーザー brthyyjpbrthyyjp
提出日時 2021-03-07 16:29:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 73,112 KB
最終ジャッジ日時 2024-04-17 08:25:22
合計ジャッジ時間 5,532 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,916 KB
testcase_01 AC 38 ms
53,136 KB
testcase_02 AC 38 ms
53,204 KB
testcase_03 AC 41 ms
57,844 KB
testcase_04 AC 38 ms
53,420 KB
testcase_05 AC 35 ms
52,960 KB
testcase_06 AC 36 ms
53,080 KB
testcase_07 AC 38 ms
52,264 KB
testcase_08 AC 38 ms
52,728 KB
testcase_09 AC 37 ms
52,660 KB
testcase_10 AC 41 ms
53,544 KB
testcase_11 AC 37 ms
53,196 KB
testcase_12 AC 36 ms
53,016 KB
testcase_13 AC 35 ms
52,596 KB
testcase_14 AC 34 ms
52,948 KB
testcase_15 AC 37 ms
54,072 KB
testcase_16 AC 46 ms
60,640 KB
testcase_17 AC 37 ms
53,024 KB
testcase_18 AC 37 ms
53,212 KB
testcase_19 AC 37 ms
53,152 KB
testcase_20 AC 36 ms
53,320 KB
testcase_21 AC 37 ms
52,688 KB
testcase_22 AC 37 ms
53,616 KB
testcase_23 AC 39 ms
52,532 KB
testcase_24 AC 38 ms
53,548 KB
testcase_25 AC 37 ms
52,808 KB
testcase_26 AC 40 ms
52,468 KB
testcase_27 AC 38 ms
53,092 KB
testcase_28 AC 38 ms
53,016 KB
testcase_29 AC 37 ms
52,768 KB
testcase_30 AC 37 ms
53,044 KB
testcase_31 AC 37 ms
52,796 KB
testcase_32 AC 37 ms
52,836 KB
testcase_33 AC 36 ms
52,752 KB
testcase_34 AC 38 ms
53,572 KB
testcase_35 AC 38 ms
52,560 KB
testcase_36 AC 38 ms
52,372 KB
testcase_37 AC 38 ms
53,260 KB
testcase_38 AC 37 ms
52,076 KB
testcase_39 AC 38 ms
53,792 KB
testcase_40 AC 50 ms
63,496 KB
testcase_41 AC 50 ms
63,032 KB
testcase_42 AC 48 ms
63,292 KB
testcase_43 AC 47 ms
62,800 KB
testcase_44 AC 50 ms
62,368 KB
testcase_45 AC 52 ms
62,900 KB
testcase_46 AC 52 ms
63,592 KB
testcase_47 AC 47 ms
62,672 KB
testcase_48 AC 51 ms
63,636 KB
testcase_49 AC 47 ms
61,908 KB
testcase_50 AC 49 ms
62,860 KB
testcase_51 AC 51 ms
63,492 KB
testcase_52 AC 49 ms
62,864 KB
testcase_53 AC 52 ms
64,680 KB
testcase_54 AC 48 ms
63,096 KB
testcase_55 AC 48 ms
62,064 KB
testcase_56 AC 50 ms
63,272 KB
testcase_57 AC 48 ms
62,860 KB
testcase_58 AC 52 ms
64,096 KB
testcase_59 AC 51 ms
63,364 KB
testcase_60 AC 47 ms
60,740 KB
testcase_61 AC 38 ms
53,472 KB
testcase_62 AC 72 ms
73,112 KB
testcase_63 AC 52 ms
62,652 KB
testcase_64 AC 53 ms
64,936 KB
testcase_65 AC 73 ms
72,160 KB
testcase_66 AC 71 ms
71,892 KB
testcase_67 AC 70 ms
72,512 KB
testcase_68 AC 51 ms
62,180 KB
testcase_69 AC 50 ms
62,652 KB
testcase_70 AC 41 ms
60,032 KB
testcase_71 AC 37 ms
52,800 KB
testcase_72 AC 37 ms
53,672 KB
testcase_73 AC 37 ms
52,560 KB
testcase_74 AC 37 ms
53,360 KB
testcase_75 AC 38 ms
53,196 KB
testcase_76 AC 37 ms
52,524 KB
testcase_77 AC 37 ms
54,116 KB
testcase_78 AC 36 ms
52,720 KB
testcase_79 AC 42 ms
59,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())

INF = 10**18
d = [[INF]*n for _ in range(n)]
for i in range(n):
    d[i][i] = 0

for i in range(m):
    s, t, w = map(int, input().split())
    s, t = s-1, t-1
    d[s][t] = min(d[s][t], w)

def warshal_floyd(d):
    n = len(d)
    for k in range(n):
        for i in range(n):
            if d[i][k] == INF:
                continue
            for j in range(n):
                if d[k][j] == INF:
                    continue
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d

d = warshal_floyd(d)
ans = [0]*n
for i in range(n):
    for j in range(n):
        if d[i][j] == INF:
            continue
        ans[i] += d[i][j]
print(*ans, sep='\n')
0