結果

問題 No.17 2つの地点に泊まりたい
ユーザー nsd_fbnsd_fb
提出日時 2015-02-20 11:45:59
言語 Python2
(2.7.18)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 557 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 6,640 KB
実行使用メモリ 6,292 KB
最終ジャッジ日時 2023-08-05 03:32:51
合計ジャッジ時間 2,205 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,064 KB
testcase_01 AC 12 ms
5,988 KB
testcase_02 AC 13 ms
6,048 KB
testcase_03 AC 72 ms
6,032 KB
testcase_04 AC 17 ms
6,112 KB
testcase_05 AC 50 ms
6,088 KB
testcase_06 AC 37 ms
6,084 KB
testcase_07 AC 28 ms
6,044 KB
testcase_08 AC 74 ms
6,208 KB
testcase_09 AC 75 ms
5,992 KB
testcase_10 AC 64 ms
6,068 KB
testcase_11 AC 74 ms
6,004 KB
testcase_12 AC 12 ms
6,160 KB
testcase_13 AC 12 ms
6,064 KB
testcase_14 AC 12 ms
6,052 KB
testcase_15 AC 12 ms
6,112 KB
testcase_16 AC 12 ms
6,004 KB
testcase_17 AC 19 ms
6,164 KB
testcase_18 AC 60 ms
6,292 KB
testcase_19 AC 54 ms
6,088 KB
testcase_20 AC 17 ms
6,024 KB
testcase_21 AC 13 ms
6,052 KB
testcase_22 AC 67 ms
6,092 KB
testcase_23 AC 47 ms
6,200 KB
testcase_24 AC 57 ms
6,204 KB
testcase_25 AC 13 ms
5,988 KB
testcase_26 AC 67 ms
6,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = input()
S = [input() for _ in xrange(N)]
M = input()

dist = [[float("inf")] * N for _ in xrange(N)]
for i in xrange(M):
    A, B, C = map(int, raw_input().split())
    dist[A][B] = dist[B][A] = C

for k in xrange(N):
    for i in xrange(N):
        for j in xrange(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

ans = float("inf")
for i in xrange(1, N - 1):
    for j in xrange(1, N - 1):
        if i == j:
            continue

        ans = min(ans, dist[0][i] + dist[i][j] + dist[j][N - 1] + S[i] + S[j])
        
print ans
0