結果

問題 No.17 2つの地点に泊まりたい
ユーザー nbisconbisco
提出日時 2016-04-17 18:06:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 798 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-23 02:13:18
合計ジャッジ時間 2,539 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 32 ms
10,880 KB
testcase_03 AC 111 ms
11,008 KB
testcase_04 AC 35 ms
10,880 KB
testcase_05 AC 72 ms
10,880 KB
testcase_06 AC 55 ms
10,880 KB
testcase_07 AC 48 ms
10,880 KB
testcase_08 AC 118 ms
11,008 KB
testcase_09 AC 112 ms
11,008 KB
testcase_10 AC 98 ms
10,880 KB
testcase_11 AC 105 ms
10,880 KB
testcase_12 AC 27 ms
10,752 KB
testcase_13 AC 28 ms
10,752 KB
testcase_14 AC 27 ms
10,752 KB
testcase_15 AC 26 ms
10,752 KB
testcase_16 AC 26 ms
10,880 KB
testcase_17 AC 38 ms
10,880 KB
testcase_18 AC 90 ms
10,880 KB
testcase_19 AC 81 ms
10,880 KB
testcase_20 AC 33 ms
10,880 KB
testcase_21 AC 29 ms
10,624 KB
testcase_22 AC 97 ms
10,880 KB
testcase_23 AC 71 ms
10,880 KB
testcase_24 AC 87 ms
10,880 KB
testcase_25 AC 27 ms
10,880 KB
testcase_26 AC 96 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
#fileencoding: utf-8

N = int(input())
S = [int(input()) for i in range(N)]
costs = [[int(j) for j in input().strip().split(" ")] for i in range(int(input()))]

cost_map = [[1<<31]*N for i in range(N)]
for cost in costs:
    cost_map[cost[0]][cost[1]] = cost[2]
    cost_map[cost[1]][cost[0]] = cost[2]

# warshall_froyd
for i in range(N):  # 経由
    for j in range(N): # start
        for k in range(N): # goal
            if j == k:
                cost_map[j][k] = 0
            else:
                cost_map[j][k] = min(cost_map[j][k],cost_map[j][i]+cost_map[i][k])

result = 1000000
for i in range(1,N-1):
    for j in range(1,N-1):
        if i != j:
            result = min(result, cost_map[0][i] + cost_map[i][j] + cost_map[j][N-1] + S[i] + S[j])

print(result)
0