結果

問題 No.1344 Typical Shortest Path Sum
ユーザー arahi10arahi10
提出日時 2021-02-19 20:09:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 8,380 KB
最終ジャッジ日時 2023-10-14 22:30:40
合計ジャッジ時間 8,836 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,108 KB
testcase_01 AC 15 ms
8,004 KB
testcase_02 AC 16 ms
8,032 KB
testcase_03 AC 19 ms
8,004 KB
testcase_04 AC 17 ms
8,164 KB
testcase_05 AC 15 ms
8,012 KB
testcase_06 AC 15 ms
8,028 KB
testcase_07 AC 16 ms
8,128 KB
testcase_08 AC 16 ms
8,100 KB
testcase_09 AC 16 ms
8,064 KB
testcase_10 AC 17 ms
8,124 KB
testcase_11 AC 16 ms
7,984 KB
testcase_12 AC 15 ms
7,980 KB
testcase_13 AC 15 ms
8,012 KB
testcase_14 AC 16 ms
8,004 KB
testcase_15 AC 15 ms
8,180 KB
testcase_16 AC 43 ms
8,000 KB
testcase_17 AC 16 ms
7,976 KB
testcase_18 AC 15 ms
8,064 KB
testcase_19 AC 16 ms
7,976 KB
testcase_20 AC 16 ms
8,012 KB
testcase_21 AC 16 ms
7,956 KB
testcase_22 AC 15 ms
8,128 KB
testcase_23 AC 16 ms
8,156 KB
testcase_24 AC 15 ms
8,052 KB
testcase_25 AC 16 ms
8,028 KB
testcase_26 AC 16 ms
8,012 KB
testcase_27 AC 16 ms
8,180 KB
testcase_28 AC 16 ms
8,044 KB
testcase_29 AC 15 ms
8,124 KB
testcase_30 AC 16 ms
8,020 KB
testcase_31 AC 15 ms
8,104 KB
testcase_32 AC 16 ms
8,132 KB
testcase_33 AC 15 ms
8,024 KB
testcase_34 AC 15 ms
7,980 KB
testcase_35 AC 16 ms
7,988 KB
testcase_36 AC 16 ms
8,024 KB
testcase_37 AC 15 ms
8,068 KB
testcase_38 AC 15 ms
8,104 KB
testcase_39 AC 16 ms
7,984 KB
testcase_40 AC 251 ms
7,980 KB
testcase_41 AC 283 ms
8,064 KB
testcase_42 AC 237 ms
8,036 KB
testcase_43 AC 229 ms
8,028 KB
testcase_44 AC 235 ms
8,032 KB
testcase_45 AC 241 ms
8,172 KB
testcase_46 AC 272 ms
7,988 KB
testcase_47 AC 258 ms
7,976 KB
testcase_48 AC 283 ms
8,000 KB
testcase_49 AC 236 ms
8,036 KB
testcase_50 AC 223 ms
8,028 KB
testcase_51 AC 243 ms
7,976 KB
testcase_52 AC 236 ms
8,044 KB
testcase_53 AC 278 ms
8,012 KB
testcase_54 AC 228 ms
7,996 KB
testcase_55 AC 244 ms
8,056 KB
testcase_56 AC 261 ms
7,980 KB
testcase_57 AC 217 ms
7,952 KB
testcase_58 AC 289 ms
8,124 KB
testcase_59 AC 274 ms
8,124 KB
testcase_60 AC 17 ms
8,288 KB
testcase_61 AC 16 ms
8,112 KB
testcase_62 AC 35 ms
8,120 KB
testcase_63 AC 19 ms
8,268 KB
testcase_64 AC 22 ms
8,032 KB
testcase_65 AC 38 ms
8,056 KB
testcase_66 AC 35 ms
8,380 KB
testcase_67 AC 35 ms
8,376 KB
testcase_68 AC 19 ms
8,224 KB
testcase_69 AC 19 ms
8,236 KB
testcase_70 AC 17 ms
8,056 KB
testcase_71 AC 15 ms
8,032 KB
testcase_72 AC 15 ms
8,120 KB
testcase_73 AC 15 ms
7,988 KB
testcase_74 AC 15 ms
7,952 KB
testcase_75 AC 16 ms
8,104 KB
testcase_76 AC 15 ms
7,956 KB
testcase_77 AC 15 ms
7,996 KB
testcase_78 AC 15 ms
8,012 KB
testcase_79 AC 26 ms
8,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import  heappop, heappush
n,m=map(int,input().split())

class WarshallFloyd:
    #O(V^3)で任意2頂点の最短距離
    def __init__(self,n,_first_index=0):
        self.v = n
        self._first_idx=_first_index
        self.d = [[float("INF")]*(n) for _ in range(n)]
        for i in range(n):
            self.d[i][i] = 0

    def path(self,x,y,c):
        if x == y:
            return False
        f=self._first_idx
        self.d[x-f][y-f] = min(c,self.d[x-f][y-f])
        #self.d[y-f][x-f] = c
        return True

    def build(self):
        for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
        for x in self.d:
            print(sum(c for c in x if c!=float("INF")))
w=WarshallFloyd(n,1)
for i in range(m):
    w.path(*map(int,input().split()))
w.build()
0