結果

問題 No.1690 Power Grid
ユーザー 👑 tamatotamato
提出日時 2021-09-24 21:56:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 767 ms / 3,000 ms
コード長 1,387 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 87,480 KB
実行使用メモリ 108,436 KB
最終ジャッジ日時 2023-09-18 21:16:57
合計ジャッジ時間 10,698 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,784 KB
testcase_01 AC 73 ms
71,768 KB
testcase_02 AC 73 ms
71,744 KB
testcase_03 AC 75 ms
71,768 KB
testcase_04 AC 78 ms
71,588 KB
testcase_05 AC 75 ms
71,892 KB
testcase_06 AC 364 ms
89,908 KB
testcase_07 AC 365 ms
89,952 KB
testcase_08 AC 368 ms
89,916 KB
testcase_09 AC 369 ms
89,896 KB
testcase_10 AC 90 ms
83,020 KB
testcase_11 AC 685 ms
106,548 KB
testcase_12 AC 73 ms
71,464 KB
testcase_13 AC 95 ms
76,912 KB
testcase_14 AC 159 ms
78,960 KB
testcase_15 AC 751 ms
108,400 KB
testcase_16 AC 396 ms
90,184 KB
testcase_17 AC 278 ms
83,832 KB
testcase_18 AC 203 ms
80,608 KB
testcase_19 AC 388 ms
90,080 KB
testcase_20 AC 402 ms
89,988 KB
testcase_21 AC 87 ms
80,728 KB
testcase_22 AC 707 ms
97,988 KB
testcase_23 AC 724 ms
108,436 KB
testcase_24 AC 731 ms
102,092 KB
testcase_25 AC 756 ms
104,464 KB
testcase_26 AC 767 ms
104,528 KB
testcase_27 AC 76 ms
71,768 KB
権限があれば一括ダウンロードができます

ソースコード

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):
            if dp[state] >= inf:
                continue
            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