結果

問題 No.1690 Power Grid
ユーザー asumo0729asumo0729
提出日時 2021-09-24 23:14:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,743 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 83,920 KB
最終ジャッジ日時 2023-09-18 22:20:13
合計ジャッジ時間 29,123 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
71,844 KB
testcase_01 AC 99 ms
71,732 KB
testcase_02 AC 104 ms
72,404 KB
testcase_03 AC 102 ms
71,720 KB
testcase_04 AC 101 ms
71,508 KB
testcase_05 AC 100 ms
71,688 KB
testcase_06 AC 2,945 ms
78,820 KB
testcase_07 AC 2,954 ms
78,688 KB
testcase_08 AC 2,954 ms
78,644 KB
testcase_09 AC 2,953 ms
78,608 KB
testcase_10 AC 127 ms
77,976 KB
testcase_11 AC 160 ms
78,644 KB
testcase_12 AC 101 ms
71,392 KB
testcase_13 AC 135 ms
77,992 KB
testcase_14 AC 482 ms
78,808 KB
testcase_15 AC 122 ms
77,580 KB
testcase_16 TLE -
testcase_17 AC 1,886 ms
78,680 KB
testcase_18 AC 928 ms
78,840 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from operator import itemgetter
from collections import defaultdict, deque
import heapq
import bisect
from itertools import combinations

stdin=sys.stdin
sys.setrecursionlimit(10 ** 8)

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
Yp=lambda:print('Yes')
Np=lambda:print('No')
inf = float('inf')
eps = 1e-9
sortkey = itemgetter(0)

###############################################################

N, M, K = lp()
A = lp()
edges = [[inf for _ in range(N)] for _ in range(N)]
for i in range(N):
    edges[i][i] = 0

for _ in range(M):
    x, y, z = lp()
    x -= 1; y -= 1
    edges[x][y] = z
    edges[y][x] = z

for s in range(N):
    for g in range(N):
        for mid in range(N):
            if s == mid or g == mid:
                continue
            dist = min(edges[s][g], edges[s][mid] + edges[mid][g])
            edges[s][g] = dist

citys = [i for i in range(N)]
ans = inf
for v in combinations(citys,K):
    temp = 0
    candidate = [0 for _ in range(N)]
    for city in v:
        temp += A[city]
        candidate[city] = 1
    
    for start in v:
        res = temp
        build = 1
        complete = [0 for _ in range(N)]
        finish = [start]
        complete[start] = 1
        while build < K:
            dist = inf
            nex = -1
            for now in finish:
                for ne in range(N):
                    if candidate[ne] == 1 and complete[ne] == 0 and dist > edges[now][ne]:
                        nex = ne
                        dist = edges[now][ne]
            res += dist
            complete[nex] = 1
            finish.append(nex)
            build += 1

        ans = min(ans, res)

print(ans)
0