結果

問題 No.1690 Power Grid
ユーザー mkawa2mkawa2
提出日時 2022-03-01 00:08:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,875 ms / 3,000 ms
コード長 1,453 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 80,888 KB
最終ジャッジ日時 2023-09-21 09:04:58
合計ジャッジ時間 31,262 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,236 KB
testcase_01 AC 72 ms
71,540 KB
testcase_02 AC 121 ms
78,024 KB
testcase_03 AC 74 ms
71,004 KB
testcase_04 AC 70 ms
71,180 KB
testcase_05 AC 68 ms
71,444 KB
testcase_06 AC 1,791 ms
80,588 KB
testcase_07 AC 1,763 ms
80,888 KB
testcase_08 AC 1,807 ms
80,800 KB
testcase_09 AC 1,811 ms
80,652 KB
testcase_10 AC 1,510 ms
79,884 KB
testcase_11 AC 1,486 ms
80,688 KB
testcase_12 AC 70 ms
71,524 KB
testcase_13 AC 120 ms
77,652 KB
testcase_14 AC 319 ms
78,444 KB
testcase_15 AC 1,432 ms
79,828 KB
testcase_16 AC 1,826 ms
80,804 KB
testcase_17 AC 834 ms
79,376 KB
testcase_18 AC 512 ms
78,996 KB
testcase_19 AC 1,875 ms
80,788 KB
testcase_20 AC 1,850 ms
80,604 KB
testcase_21 AC 1,516 ms
79,908 KB
testcase_22 AC 1,811 ms
80,620 KB
testcase_23 AC 1,424 ms
80,172 KB
testcase_24 AC 1,872 ms
80,600 KB
testcase_25 AC 1,801 ms
80,544 KB
testcase_26 AC 1,568 ms
80,596 KB
testcase_27 AC 70 ms
71,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

n, m, k = LI()
aa = LI()

dist = [[inf]*n for _ in range(n)]
for u in range(n): dist[u][u] = 0
for _ in range(m):
    u, v, z = LI()
    u, v = u-1, v-1
    dist[u][v] = dist[v][u] = z

for v in range(n):
    for u in range(n):
        for w in range(n):
            dist[u][w] = min(dist[u][w], dist[u][v]+dist[v][w])

def popcnt(a): return bin(a).count("1")

dp = [inf]*(1 << n)
ans = inf
for s in range(1, 1 << n):
    pc = popcnt(s)
    if pc == 1:
        dp[s] = aa[s.bit_length()-1]
    if pc == k: ans = min(ans, dp[s])
    for u in range(n):
        if s >> u & 1: continue
        ns = s | 1 << u
        cost = min(dist[u][v] for v in range(n) if s >> v & 1)+aa[u]
        dp[ns] = min(dp[ns], dp[s]+cost)

print(ans)
0