結果

問題 No.1690 Power Grid
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-09-24 22:28:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 783 ms / 3,000 ms
コード長 922 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 79,796 KB
最終ジャッジ日時 2023-09-18 21:44:40
合計ジャッジ時間 14,540 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,308 KB
testcase_01 AC 74 ms
71,536 KB
testcase_02 AC 101 ms
76,736 KB
testcase_03 AC 73 ms
71,332 KB
testcase_04 AC 73 ms
71,252 KB
testcase_05 AC 74 ms
71,236 KB
testcase_06 AC 666 ms
79,768 KB
testcase_07 AC 670 ms
79,760 KB
testcase_08 AC 673 ms
79,768 KB
testcase_09 AC 668 ms
79,736 KB
testcase_10 AC 719 ms
79,340 KB
testcase_11 AC 655 ms
79,700 KB
testcase_12 AC 76 ms
71,524 KB
testcase_13 AC 106 ms
76,916 KB
testcase_14 AC 198 ms
78,176 KB
testcase_15 AC 724 ms
79,372 KB
testcase_16 AC 709 ms
79,680 KB
testcase_17 AC 427 ms
78,972 KB
testcase_18 AC 257 ms
78,204 KB
testcase_19 AC 723 ms
79,796 KB
testcase_20 AC 736 ms
79,692 KB
testcase_21 AC 742 ms
79,396 KB
testcase_22 AC 753 ms
79,692 KB
testcase_23 AC 752 ms
79,640 KB
testcase_24 AC 783 ms
79,652 KB
testcase_25 AC 761 ms
79,652 KB
testcase_26 AC 773 ms
79,660 KB
testcase_27 AC 74 ms
71,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
inf = 10**12
dis = [[inf]*n for i in range(n)]
for i in range(n):
    dis[i][i] = 0

for i in range(m):
    x,y,z = map(int,input().split())
    x,y = x-1,y-1
    dis[x][y] = dis[y][x] = z

for t in range(n):
    for i in range(n):
        for j in range(n):
            if dis[i][t] == inf or dis[t][j] == inf:
                continue
            dis[i][j] = min(dis[i][j],dis[i][t]+dis[t][j])

dp = [inf]*(1<<n)
for i in range(n):
    dp[1<<i] = A[i]
ans = inf
for i in range(1<<n):
    if dp[i] == inf:
        continue
    if bin(i).count("1") == k:
        ans = min(ans,dp[i])
    for j in range(n):
        if i >> j & 1:
            continue
        cost = dp[i]+A[j]
        d = inf
        for t in range(n):
            if i >> t & 1:
                d = min(d,dis[t][j])
        cost += d
        dp[i|1<<j] = min(dp[i|1<<j],cost)
print(ans)
0