結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,908 KB
testcase_01 AC 35 ms
10,908 KB
testcase_02 AC 35 ms
10,912 KB
testcase_03 AC 73 ms
10,984 KB
testcase_04 AC 40 ms
10,916 KB
testcase_05 WA -
testcase_06 AC 49 ms
10,960 KB
testcase_07 AC 44 ms
10,944 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 33 ms
10,908 KB
testcase_13 AC 34 ms
10,908 KB
testcase_14 AC 32 ms
10,908 KB
testcase_15 AC 32 ms
10,908 KB
testcase_16 AC 34 ms
10,908 KB
testcase_17 AC 38 ms
10,912 KB
testcase_18 AC 60 ms
10,960 KB
testcase_19 AC 57 ms
10,940 KB
testcase_20 WA -
testcase_21 AC 35 ms
10,908 KB
testcase_22 AC 65 ms
10,972 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 35 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 in range(1, N - 1):
        for b in range(1, N - 1):
            if a == b:
                continue
            cost = S[a] + S[b] + edge[0][a] + edge[a][b] + edge[b][N - 1]
            ans = min(ans, cost)

    return ans


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


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