結果

問題 No.17 2つの地点に泊まりたい
ユーザー convexineqconvexineq
提出日時 2020-12-06 04:11:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 74 ms / 5,000 ms
コード長 626 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 81,796 KB
実行使用メモリ 72,944 KB
最終ジャッジ日時 2023-10-17 03:31:31
合計ジャッジ時間 3,029 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 41 ms
59,616 KB
testcase_03 AC 47 ms
62,056 KB
testcase_04 AC 45 ms
61,692 KB
testcase_05 AC 60 ms
68,280 KB
testcase_06 AC 53 ms
64,104 KB
testcase_07 AC 50 ms
63,752 KB
testcase_08 AC 74 ms
72,944 KB
testcase_09 AC 70 ms
72,944 KB
testcase_10 AC 51 ms
64,104 KB
testcase_11 AC 55 ms
66,152 KB
testcase_12 AC 35 ms
53,460 KB
testcase_13 AC 34 ms
53,460 KB
testcase_14 AC 36 ms
53,460 KB
testcase_15 AC 35 ms
53,460 KB
testcase_16 AC 35 ms
53,460 KB
testcase_17 AC 42 ms
59,644 KB
testcase_18 AC 45 ms
62,044 KB
testcase_19 AC 46 ms
62,044 KB
testcase_20 AC 41 ms
59,632 KB
testcase_21 AC 40 ms
59,292 KB
testcase_22 AC 48 ms
62,056 KB
testcase_23 AC 58 ms
66,144 KB
testcase_24 AC 55 ms
66,152 KB
testcase_25 AC 41 ms
59,292 KB
testcase_26 AC 61 ms
68,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Floyd_Warshall(dist):
    n = len(dist)
    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])

n = int(input())
s = [0]*n
for i in range(n):
    s[i] = int(input())
INF = 10**9
dist = [[INF]*n for _ in range(n)]
m = int(input())
for _ in range(m):
    a,b,c = map(int,input().split())
    dist[a][b] = dist[b][a] = c

Floyd_Warshall(dist)

ans = INF
for i in range(1,n-1):
    for j in range(1,n-1):
        if i==j: continue
        d = dist[0][i] + dist[i][j] + dist[j][n-1] + s[i] + s[j]
        ans = min(ans,d)
print(ans)
0