結果

問題 No.1690 Power Grid
ユーザー LyricalMaestroLyricalMaestro
提出日時 2024-02-19 02:49:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,370 bytes
コンパイル時間 605 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,076 KB
最終ジャッジ日時 2024-02-19 02:49:36
合計ジャッジ時間 5,565 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 47 ms
62,092 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 42 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 208 ms
75,536 KB
testcase_07 AC 193 ms
75,536 KB
testcase_08 AC 190 ms
75,536 KB
testcase_09 AC 183 ms
75,536 KB
testcase_10 AC 137 ms
75,520 KB
testcase_11 AC 137 ms
75,468 KB
testcase_12 AC 36 ms
53,460 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 131 ms
75,532 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 36 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1690


def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    edges = []
    for _ in range(M):
        x, y, z = map(int, input().split())
        edges.append((x - 1, y - 1, z))

    # 2点間の距離を求める
    dist_matrix = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        dist_matrix[i][i] = 0
    for x, y, z in edges:
        dist_matrix[x][y] = z
        dist_matrix[y][x] = z
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist_matrix[i][j] = min(dist_matrix[i][j], dist_matrix[i][k] + dist_matrix[k][j])
    
    answer_cost = float("inf")
    for bit in range(2 ** N):
        count = 0
        array = []
        cost = 0
        for i in range(N):
            if bit >> i & 1:
                cost += A[i]
                count += 1
                array.append(i)
        
        if count == K:
            for i0 in range(len(array)):
                min_cost = float("inf")
                for i1 in range(i0):
                    min_cost = min(min_cost, dist_matrix[array[i0]][array[i1]])
                if min_cost < float("inf"):
                    cost += min_cost
            answer_cost = min(answer_cost, cost)
    print(answer_cost)

        
    



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