結果

問題 No.17 2つの地点に泊まりたい
ユーザー dangodango
提出日時 2023-07-08 17:53:25
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 944 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 82,884 KB
最終ジャッジ日時 2023-09-29 19:16:01
合計ジャッジ時間 5,563 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,188 KB
testcase_01 AC 75 ms
71,336 KB
testcase_02 AC 87 ms
76,144 KB
testcase_03 AC 123 ms
77,008 KB
testcase_04 AC 95 ms
76,348 KB
testcase_05 AC 137 ms
77,844 KB
testcase_06 AC 116 ms
77,388 KB
testcase_07 AC 106 ms
76,416 KB
testcase_08 AC 171 ms
79,048 KB
testcase_09 AC 167 ms
78,788 KB
testcase_10 AC 140 ms
77,508 KB
testcase_11 AC 147 ms
77,752 KB
testcase_12 AC 74 ms
71,296 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 125 ms
77,348 KB
testcase_24 AC 134 ms
77,392 KB
testcase_25 AC 81 ms
75,796 KB
testcase_26 AC 148 ms
77,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import product

def main():
    n = int(input())
    ss = [int(input()) for _ in range(n)]
    m = int(input())
    abcs = [list(map(int, input().split())) for _ in range(m)]
    print(stay2(n, ss, abcs))

def stay2(n, ss, abcs):
    return min(fullSearch(n, ss, warshallFloyd(n, abcs)))

def fullSearch(n, ss, g):
    res = []
    for s1 in range(1, n - 1):
        for s2 in range(1, n - 1):
            if s1 != s2:
                res.append(g[(0, s1)] + g[(s1, s2)] + g[(s2, n - 1)] + ss[s1] + ss[s2])
    return res

def warshallFloyd(n, abcs):
    g0 = {}
    for a, b, c in abcs:
        g0[(a, b)] = c
        g0[(b, a)] = c
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if (i, k) in g0 and (k, j) in g0:
                    if (i, j) not in g0 or g0[(i, j)] > g0[(i, k)] + g0[(k, j)]:
                        g0[(i, j)] = g0[(i, k)] + g0[(k, j)]
    return g0

main()
0