結果

問題 No.1690 Power Grid
ユーザー rin204rin204
提出日時 2022-01-25 17:24:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 889 ms / 3,000 ms
コード長 822 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 78,960 KB
最終ジャッジ日時 2024-05-09 18:00:52
合計ジャッジ時間 14,005 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,096 KB
testcase_01 AC 36 ms
52,224 KB
testcase_02 AC 57 ms
66,944 KB
testcase_03 AC 35 ms
52,736 KB
testcase_04 AC 35 ms
52,096 KB
testcase_05 AC 36 ms
52,608 KB
testcase_06 AC 663 ms
78,668 KB
testcase_07 AC 678 ms
78,492 KB
testcase_08 AC 670 ms
78,336 KB
testcase_09 AC 682 ms
78,364 KB
testcase_10 AC 695 ms
78,336 KB
testcase_11 AC 692 ms
78,448 KB
testcase_12 AC 35 ms
52,864 KB
testcase_13 AC 57 ms
67,636 KB
testcase_14 AC 140 ms
76,800 KB
testcase_15 AC 662 ms
78,208 KB
testcase_16 AC 822 ms
78,464 KB
testcase_17 AC 392 ms
77,696 KB
testcase_18 AC 194 ms
77,020 KB
testcase_19 AC 660 ms
78,960 KB
testcase_20 AC 839 ms
78,592 KB
testcase_21 AC 654 ms
78,336 KB
testcase_22 AC 702 ms
78,620 KB
testcase_23 AC 661 ms
78,336 KB
testcase_24 AC 818 ms
78,744 KB
testcase_25 AC 889 ms
78,592 KB
testcase_26 AC 700 ms
78,720 KB
testcase_27 AC 37 ms
52,224 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