結果

問題 No.1690 Power Grid
ユーザー rlangevinrlangevin
提出日時 2023-02-14 23:37:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 696 ms / 3,000 ms
コード長 932 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 86,700 KB
実行使用メモリ 79,428 KB
最終ジャッジ日時 2023-09-24 10:26:28
合計ジャッジ時間 14,114 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,268 KB
testcase_01 AC 73 ms
71,208 KB
testcase_02 AC 91 ms
76,524 KB
testcase_03 AC 73 ms
71,088 KB
testcase_04 AC 74 ms
71,428 KB
testcase_05 AC 72 ms
71,256 KB
testcase_06 AC 578 ms
79,332 KB
testcase_07 AC 577 ms
79,324 KB
testcase_08 AC 579 ms
79,252 KB
testcase_09 AC 576 ms
79,352 KB
testcase_10 AC 637 ms
79,208 KB
testcase_11 AC 574 ms
79,336 KB
testcase_12 AC 74 ms
71,388 KB
testcase_13 AC 94 ms
76,532 KB
testcase_14 AC 161 ms
77,548 KB
testcase_15 AC 668 ms
79,204 KB
testcase_16 AC 669 ms
79,220 KB
testcase_17 AC 356 ms
78,080 KB
testcase_18 AC 281 ms
77,736 KB
testcase_19 AC 663 ms
79,428 KB
testcase_20 AC 685 ms
79,268 KB
testcase_21 AC 677 ms
79,212 KB
testcase_22 AC 665 ms
79,420 KB
testcase_23 AC 672 ms
79,236 KB
testcase_24 AC 682 ms
79,252 KB
testcase_25 AC 656 ms
79,380 KB
testcase_26 AC 696 ms
79,308 KB
testcase_27 AC 74 ms
71,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def popcount(n):
    cnt = 0
    while n:
        cnt += n & 1
        n //= 2
    return cnt

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
inf = 10 ** 18
G = [[inf] * N for i in range(N)]
for i in range(M):
    X, Y, Z = map(int, input().split())
    X, Y = X - 1, Y - 1
    G[X][Y] = Z
    G[Y][X] = Z
    
for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j])
            
N2 = 1 << N
dp = [inf] * N2
for i in range(N):
    dp[1 << i] = A[i]
    
for s in range(1, N2):
    for i in range(N):
        if (s >> i) & 1:
            continue
        d = inf
        for j in range(N):
            if (s >> j) & 1:
                d = min(d, G[i][j])                
        dp[s | 1 << i] = min(dp[s | 1 << i], dp[s] + A[i] + d)
     
ans = inf   
for s in range(1, N2):
    if popcount(s) == K:
        ans = min(ans, dp[s])
print(ans)
0