結果

問題 No.1344 Typical Shortest Path Sum
ユーザー tnodino
提出日時 2022-05-06 19:01:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 687 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2024-07-05 20:04:38
合計ジャッジ時間 5,488 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 WA * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

def BellmanFord(N, G, s):
    INF = 1<<64
    dist = [INF for _ in range(N)]
    dist[s] = 0
    for cnt in range(N):
        Update = False
        for pos,nxt,cost in G:
            if dist[pos] + cost < dist[nxt]:
                dist[nxt] = dist[pos] + cost
                Update = True
        if not Update:
            break
        if cnt == N - 1:
            return -1
    return dist

INF = 1<<64
N,M = map(int,input().split())
G = []
for _ in range(M):
    s,t,d = map(int,input().split())
    s -= 1
    t -= 1
    G.append((s, t, d))
for i in range(N):
    dist = BellmanFord(N, G, i)
    ans = 0
    for d in dist:
        if d != INF:
            ans += d
    print(ans)
0