結果

問題 No.1690 Power Grid
ユーザー 👑 rin204rin204
提出日時 2022-01-25 17:24:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 927 ms / 3,000 ms
コード長 822 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 79,940 KB
最終ジャッジ日時 2023-08-22 12:20:06
合計ジャッジ時間 17,330 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,444 KB
testcase_01 AC 76 ms
71,372 KB
testcase_02 AC 98 ms
76,856 KB
testcase_03 AC 75 ms
71,728 KB
testcase_04 AC 75 ms
71,180 KB
testcase_05 AC 72 ms
71,572 KB
testcase_06 AC 746 ms
79,772 KB
testcase_07 AC 748 ms
79,704 KB
testcase_08 AC 747 ms
79,564 KB
testcase_09 AC 753 ms
79,688 KB
testcase_10 AC 754 ms
79,512 KB
testcase_11 AC 766 ms
79,760 KB
testcase_12 AC 73 ms
71,672 KB
testcase_13 AC 94 ms
76,696 KB
testcase_14 AC 180 ms
78,040 KB
testcase_15 AC 735 ms
79,532 KB
testcase_16 AC 914 ms
79,580 KB
testcase_17 AC 454 ms
79,068 KB
testcase_18 AC 239 ms
78,420 KB
testcase_19 AC 781 ms
79,564 KB
testcase_20 AC 927 ms
79,940 KB
testcase_21 AC 728 ms
79,432 KB
testcase_22 AC 773 ms
79,852 KB
testcase_23 AC 737 ms
79,612 KB
testcase_24 AC 885 ms
79,752 KB
testcase_25 AC 881 ms
79,692 KB
testcase_26 AC 776 ms
79,752 KB
testcase_27 AC 73 ms
71,364 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