結果

問題 No.17 2つの地点に泊まりたい
ユーザー KudeKude
提出日時 2020-09-04 02:46:57
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 115 ms / 5,000 ms
コード長 614 bytes
コンパイル時間 755 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 77,684 KB
最終ジャッジ日時 2023-08-16 03:28:47
合計ジャッジ時間 4,364 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,280 KB
testcase_01 AC 77 ms
71,440 KB
testcase_02 AC 82 ms
76,268 KB
testcase_03 AC 91 ms
76,692 KB
testcase_04 AC 86 ms
76,368 KB
testcase_05 AC 104 ms
76,772 KB
testcase_06 AC 96 ms
76,416 KB
testcase_07 AC 90 ms
76,504 KB
testcase_08 AC 115 ms
77,576 KB
testcase_09 AC 115 ms
77,684 KB
testcase_10 AC 94 ms
76,412 KB
testcase_11 AC 98 ms
76,188 KB
testcase_12 AC 75 ms
71,480 KB
testcase_13 AC 78 ms
71,248 KB
testcase_14 AC 74 ms
71,380 KB
testcase_15 AC 77 ms
71,448 KB
testcase_16 AC 76 ms
71,328 KB
testcase_17 AC 84 ms
76,556 KB
testcase_18 AC 89 ms
76,468 KB
testcase_19 AC 89 ms
76,468 KB
testcase_20 AC 82 ms
76,440 KB
testcase_21 AC 79 ms
75,880 KB
testcase_22 AC 90 ms
76,484 KB
testcase_23 AC 99 ms
76,540 KB
testcase_24 AC 97 ms
76,508 KB
testcase_25 AC 81 ms
75,884 KB
testcase_26 AC 102 ms
76,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = [int(input()) for _ in range(n)]
INF = 10**18
dist = [[INF] * n for _ in range(n)]
for _ in range(int(input())):
    a, b, c = map(int, input().split())
    dist[a][b] = c
    dist[b][a] = c
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])

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