結果

問題 No.1690 Power Grid
ユーザー tamatotamato
提出日時 2021-09-24 21:53:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,329 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 77,076 KB
最終ジャッジ日時 2023-09-18 21:14:26
合計ジャッジ時間 5,847 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,988 KB
testcase_01 AC 74 ms
71,752 KB
testcase_02 AC 100 ms
77,076 KB
testcase_03 AC 74 ms
71,684 KB
testcase_04 AC 74 ms
71,708 KB
testcase_05 AC 72 ms
71,696 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 #

mod = 1000000007
eps = 10**-9
inf = 10 ** 17


def main():
    import sys
    input = sys.stdin.readline

    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    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 v in range(N):
        dist[v][v] = 0

    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)
    dp[0] = 0
    for _ in range(K):
        dp_new = [inf] * (1 << N)
        for state in range(1 << N):
            for i in range(N):
                if state >> i & 1:
                    continue
                state_new = state | (1 << i)
                if state == 0:
                    dp_new[state_new] = min(dp_new[state_new], dp[state] + A[i])
                else:
                    min_cost = inf
                    for j in range(N):
                        if state >> j & 1:
                            min_cost = min(min_cost, dist[i][j])
                    dp_new[state_new] = min(dp_new[state_new], dp[state] + A[i] + min_cost)
        dp = dp_new
    print(min(dp))


if __name__ == '__main__':
    main()
0