結果

問題 No.17 2つの地点に泊まりたい
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-03-01 00:08:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,286 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 81,600 KB
実行使用メモリ 76,456 KB
最終ジャッジ日時 2023-10-24 19:16:13
合計ジャッジ時間 2,598 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,780 KB
testcase_01 AC 36 ms
53,780 KB
testcase_02 AC 39 ms
59,728 KB
testcase_03 AC 56 ms
70,632 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 56 ms
66,420 KB
testcase_08 AC 85 ms
76,452 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 35 ms
53,780 KB
testcase_13 AC 35 ms
53,780 KB
testcase_14 AC 35 ms
53,780 KB
testcase_15 AC 34 ms
53,780 KB
testcase_16 AC 34 ms
53,780 KB
testcase_17 AC 41 ms
61,796 KB
testcase_18 AC 52 ms
68,604 KB
testcase_19 AC 51 ms
68,604 KB
testcase_20 AC 40 ms
59,748 KB
testcase_21 AC 39 ms
59,748 KB
testcase_22 AC 55 ms
68,604 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 41 ms
59,748 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3
# -*- coding: utf-8 -*-

import array
import itertools


INF = 2 ** 25


class WarshallFloyd(object):

    def __init__(self, max_v, edges):
        self.max_v = max_v
        self.dist = edges
        for v in range(max_v):
            self.dist[v][v] = 0

    def compute(self):
        for u, v, w in itertools.product(range(self.max_v), repeat=3):
            new_length = self.dist[u][v] + self.dist[v][w]
            self.dist[u][w] = min(self.dist[u][w], new_length)
        return self.dist


def main():
    n = int(input())
    stay_costs = array.array("I", (int(input()) for _ in range(n)))
    m = int(input())
    edges = [array.array("I", (INF for _ in range(n))) for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        edges[a][b] = c
        edges[b][a] = c
    wf = WarshallFloyd(n, edges)
    move_costs = wf.compute()
    answer = INF
    for u0, v0 in itertools.combinations(range(1, n - 1), 2):
        for u, v in [(u0, v0), (v0, u0)]:
            move_cost = move_costs[0][u] + \
                move_costs[u][v] + move_costs[v][n - 1]
            stay_cost = stay_costs[u] + stay_costs[v]
            answer = min(answer, move_cost + stay_cost)
    print(answer)


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