結果

問題 No.1690 Power Grid
ユーザー tobusakanatobusakana
提出日時 2023-11-01 00:44:47
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,401 bytes
コンパイル時間 1,043 ms
コンパイル使用メモリ 81,844 KB
実行使用メモリ 136,708 KB
最終ジャッジ日時 2023-11-01 00:44:53
合計ジャッジ時間 6,078 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,596 KB
testcase_01 AC 36 ms
53,596 KB
testcase_02 AC 77 ms
73,880 KB
testcase_03 AC 36 ms
53,596 KB
testcase_04 AC 36 ms
53,596 KB
testcase_05 AC 38 ms
53,596 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
    print(min(A))
    exit(0)
INF = 1 << 60
dist = [[INF] * N for i in range(N)]
for i in range(N):
    dist[i][i] = 0

for _ in range(M):
    x,y,z = map(int,input().split())
    dist[x - 1][y - 1] = z
    dist[y - 1][x - 1] = 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])
            
def popcnt(x):
    res = 0
    while x:
        res += (x & 1)
        x >>= 1
    return res

dp = [[INF] * N for i in range(1 << N)]
for i in range(N):
    dp[1 << i][i] = A[i]
    
for status in range(1 << N):
    for from_v in range(N):
        if (status >> from_v) & 1 == 0:
            continue
        for to_v in range(N):
            if (status >> to_v) & 1:
                continue
            next_status = status | (1 << to_v)
            shortest = INF
            for s in range(N):
                if (status >> s) & 1 == 0:
                    continue
                shortest = min(shortest, dist[s][to_v])
            dp[next_status][to_v] = min(dp[next_status][to_v], dp[status][from_v] + shortest + A[to_v])
ans = INF          
for status in range(1 << N):
    if popcnt(status) == K:
        for v in range(N):
            ans = min(ans, dp[status][v])
            
print(ans)
    
            
            
        


0