結果

問題 No.1690 Power Grid
ユーザー roarisroaris
提出日時 2021-09-24 23:01:53
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,022 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 119,284 KB
最終ジャッジ日時 2023-09-18 22:00:00
合計ジャッジ時間 16,698 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
76,108 KB
testcase_01 AC 98 ms
71,800 KB
testcase_02 AC 118 ms
77,584 KB
testcase_03 AC 96 ms
71,640 KB
testcase_04 AC 98 ms
71,600 KB
testcase_05 AC 98 ms
71,600 KB
testcase_06 AC 2,525 ms
98,788 KB
testcase_07 AC 2,491 ms
98,604 KB
testcase_08 AC 2,494 ms
98,576 KB
testcase_09 AC 2,483 ms
98,480 KB
testcase_10 AC 827 ms
84,000 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
d = [[10**18]*N for _ in range(N)]

for i in range(N):
    d[i][i] = 0

for _ in range(M):
    X, Y, Z = map(int, input().split())
    d[X-1][Y-1] = Z
    d[Y-1][X-1] = Z

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])

dp = [[10**18]*(1<<N) for _ in range(K+1)]
dp[0][0] = 0

for i in range(K):
    for S in range(1<<N):
        l1, l2 = [], []
        
        for v in range(N):
            if (S>>v)&1:
                l1.append(v)
            else:
                l2.append(v)
                
        for v in l2:
            if S==0:
                cost = 0
            else:
                cost = 10**18
            
                for nv in l1:
                    cost = min(cost, d[v][nv])
            
            dp[i+1][S|(1<<v)] = min(dp[i+1][S|(1<<v)], dp[i][S]+A[v]+cost)

print(min(dp[K]))
0