結果

問題 No.17 2つの地点に泊まりたい
ユーザー sue_charosue_charo
提出日時 2017-06-01 20:14:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,338 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 11,988 KB
実行使用メモリ 11,028 KB
最終ジャッジ日時 2023-10-21 20:16:41
合計ジャッジ時間 2,880 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
10,908 KB
testcase_01 AC 35 ms
10,908 KB
testcase_02 AC 37 ms
10,912 KB
testcase_03 AC 73 ms
10,984 KB
testcase_04 AC 39 ms
10,916 KB
testcase_05 WA -
testcase_06 AC 50 ms
10,968 KB
testcase_07 AC 47 ms
10,952 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 36 ms
10,908 KB
testcase_13 AC 37 ms
10,908 KB
testcase_14 AC 35 ms
10,908 KB
testcase_15 AC 35 ms
10,908 KB
testcase_16 AC 35 ms
10,908 KB
testcase_17 AC 41 ms
10,912 KB
testcase_18 AC 65 ms
10,960 KB
testcase_19 AC 62 ms
10,940 KB
testcase_20 WA -
testcase_21 AC 36 ms
10,908 KB
testcase_22 AC 70 ms
10,972 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 37 ms
10,916 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    S = [II() for __ in range(N)]
    M = II()
    A, B, C = list(), list(), list()
    for __ in range(M):
        a, b, c = ILI()
        A.append(a)
        B.append(b)
        C.append(c)
    return (N, S, M, A, B, C)


def solve(N, S, M, A, B, C):
    edge = [[INF] * N for __ in range(N)]
    for a, b, c in zip(A, B, C):
        edge[a][b] = c
        edge[b][a] = c
    for i in range(N):
        edge[i][i] = 0
    for i in range(N):
        for j in range(N):
            for k in range(N):
                edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j])

    ans = INF

    for a, b in itertools.combinations(range(1, N - 1), 2):
        cost_1 = S[a] + S[b] + edge[0][a] + edge[a][b] + edge[b][N - 1]
        cost_2 = S[a] + S[b] + edge[0][b] + edge[b][a] + edge[a][N - 1]
        ans = min(ans, cost_1, cost_2)

    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()
0