結果

問題 No.1690 Power Grid
ユーザー brthyyjpbrthyyjp
提出日時 2021-09-24 23:06:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,324 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 164,856 KB
最終ジャッジ日時 2023-09-18 22:12:13
合計ジャッジ時間 5,448 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
164,856 KB
testcase_01 AC 74 ms
71,276 KB
testcase_02 AC 97 ms
76,556 KB
testcase_03 AC 74 ms
71,348 KB
testcase_04 AC 74 ms
71,356 KB
testcase_05 AC 74 ms
71,252 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 #

INF = 10**18

def main():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    g = [[] for i in range(n)]
    D = [[INF]*n for i in range(n)]
    for i in range(m):
        x, y, z = map(int, input().split())
        x, y = x-1, y-1
        g[x].append((z, y))
        g[y].append((z, x))
        D[x][y] = z
        D[y][x] = z

    for i in range(n):
        D[i][i] = 0

    def warshal_floyd(d):
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    d[i][j] = min(d[i][j], d[i][k]+d[k][j])
        return d

    D = warshal_floyd(D)
    dp = [INF]*(1<<n)
    dp[0] = 0
    for i in range(k):
        nx = [INF]*(1<<n)
        for s in range(1<<n):
            for v in range(n):
                if (s>>v)&1:
                    continue
                ns = s|(1<<v)
                U = []
                for u in range(n):
                    if (s>>u)&1:
                        U.append(u)
                if not U:
                    nx[ns] = min(nx[ns], dp[s]+A[v])
                else:
                    d = INF
                    for u in U:
                        d = min(d, D[v][u])
                    nx[s|ns] = min(nx[ns], dp[s]+A[v]+d)
        dp = nx
    print(min(dp))

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