結果

問題 No.17 2つの地点に泊まりたい
ユーザー tnodinotnodino
提出日時 2022-02-02 06:32:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 77,552 KB
最終ジャッジ日時 2023-09-02 02:40:37
合計ジャッジ時間 4,461 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,228 KB
testcase_01 AC 72 ms
71,096 KB
testcase_02 AC 81 ms
76,340 KB
testcase_03 AC 101 ms
77,068 KB
testcase_04 AC 81 ms
76,200 KB
testcase_05 AC 95 ms
76,740 KB
testcase_06 AC 88 ms
76,208 KB
testcase_07 AC 86 ms
76,188 KB
testcase_08 AC 106 ms
77,336 KB
testcase_09 AC 106 ms
77,552 KB
testcase_10 AC 100 ms
76,796 KB
testcase_11 AC 103 ms
76,736 KB
testcase_12 AC 71 ms
71,448 KB
testcase_13 AC 72 ms
71,436 KB
testcase_14 AC 70 ms
71,312 KB
testcase_15 AC 73 ms
71,412 KB
testcase_16 AC 74 ms
71,032 KB
testcase_17 AC 85 ms
76,076 KB
testcase_18 AC 101 ms
77,484 KB
testcase_19 AC 100 ms
76,880 KB
testcase_20 AC 84 ms
76,576 KB
testcase_21 AC 78 ms
75,652 KB
testcase_22 AC 104 ms
77,416 KB
testcase_23 AC 93 ms
76,240 KB
testcase_24 AC 102 ms
76,720 KB
testcase_25 AC 77 ms
75,412 KB
testcase_26 AC 102 ms
76,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def WarshallFloyd(N, Cost):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if Cost[i][k] + Cost[k][j] < Cost[i][j]:
                    Cost[i][j] = Cost[i][k] + Cost[k][j]
    return Cost

INF = 1<<64
N = int(input())
S = list(int(input()) for _ in range(N))
M = int(input())
Cost = [[INF] * N for _ in range(N)]
for i in range(N):
    Cost[i][i] = 0
for _ in range(M):
    A,B,C = map(int,input().split())
    Cost[A][B] = C
    Cost[B][A] = C
Cost = WarshallFloyd(N, Cost)
ans = INF
for i in range(1,N-1):
    for j in range(1,N-1):
        if i != j:
            C = Cost[0][i] + Cost[i][j] + Cost[j][N-1] + S[i] + S[j]
            ans = min(ans, C)
print(ans)
0