結果

問題 No.1690 Power Grid
ユーザー 👑 rin204rin204
提出日時 2022-01-25 17:24:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 922 ms / 3,000 ms
コード長 822 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 78,848 KB
最終ジャッジ日時 2024-12-16 09:15:51
合計ジャッジ時間 15,103 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
51,968 KB
testcase_01 AC 42 ms
51,968 KB
testcase_02 AC 69 ms
66,816 KB
testcase_03 AC 42 ms
52,224 KB
testcase_04 AC 42 ms
52,096 KB
testcase_05 AC 42 ms
52,096 KB
testcase_06 AC 738 ms
78,336 KB
testcase_07 AC 733 ms
78,464 KB
testcase_08 AC 742 ms
78,336 KB
testcase_09 AC 739 ms
78,592 KB
testcase_10 AC 738 ms
78,080 KB
testcase_11 AC 757 ms
78,464 KB
testcase_12 AC 43 ms
52,480 KB
testcase_13 AC 71 ms
67,328 KB
testcase_14 AC 165 ms
76,800 KB
testcase_15 AC 713 ms
78,464 KB
testcase_16 AC 900 ms
78,464 KB
testcase_17 AC 441 ms
77,440 KB
testcase_18 AC 226 ms
76,672 KB
testcase_19 AC 739 ms
78,592 KB
testcase_20 AC 922 ms
78,464 KB
testcase_21 AC 726 ms
78,336 KB
testcase_22 AC 779 ms
78,464 KB
testcase_23 AC 715 ms
78,080 KB
testcase_24 AC 875 ms
78,848 KB
testcase_25 AC 857 ms
78,464 KB
testcase_26 AC 774 ms
78,592 KB
testcase_27 AC 44 ms
51,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m, K = map(int, input().split())
A = list(map(int, input().split()))
inf = 1 << 60
dist = [[inf] * n for _ in range(n)]
for _ in range(m):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    dist[x][y] = z
    dist[y][x] = z
    
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

dp = [inf] * (1 << n)
for i in range(n):
    dp[1 << i] = A[i]
ans = inf
for bit in range(1, 1 << n):
    for i in range(n):
        if not bit >> i & 1:
            continue
        for j in range(n):
            if i == j or not bit >> j & 1:
                continue
            dp[bit] = min(dp[bit], dp[bit ^ (1 << j)] + dist[i][j] + A[j])
    
    if bin(bit).count("1") == K:
        ans = min(ans, dp[bit])

print(ans)
            
0