結果

問題 No.1690 Power Grid
ユーザー wolgnikwolgnik
提出日時 2021-09-24 22:49:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 874 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 77,680 KB
最終ジャッジ日時 2023-09-18 21:55:20
合計ジャッジ時間 4,409 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,268 KB
testcase_01 AC 72 ms
71,400 KB
testcase_02 AC 73 ms
71,588 KB
testcase_03 AC 76 ms
71,384 KB
testcase_04 AC 72 ms
71,448 KB
testcase_05 AC 73 ms
71,324 KB
testcase_06 AC 146 ms
77,184 KB
testcase_07 AC 145 ms
77,236 KB
testcase_08 AC 144 ms
77,332 KB
testcase_09 AC 144 ms
77,028 KB
testcase_10 AC 79 ms
76,432 KB
testcase_11 WA -
testcase_12 AC 73 ms
71,272 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 154 ms
77,404 KB
testcase_21 AC 81 ms
76,388 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 74 ms
71,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import combinations as combi
input = sys.stdin.readline
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
d = [[10 ** 18] * N for _ in range(N)]
for i in range(M):
  u, v, c = map(int, input().split())
  d[u - 1][v - 1] = c
  d[v - 1][u - 1] = c

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])

res = 10 ** 18
for c in combi(range(N), K):
  cres = 0
  s = [c[0]]
  vis = [0] * N
  while len(s):
    i = s.pop()
    vis[i] = 1
    t = 10 ** 18
    jj = 0
    for j in c:
      if vis[j]: continue
      if i == j: continue
      if t > d[i][j]:
        t = min(t, d[i][j])
        jj = j
    if t == 10 ** 18: break
    cres += t
    if vis[jj]: continue
    vis[jj] = 1
    s.append(jj)
  for i in c: cres += a[i]
  res = min(res, cres)
  #print(c, cres, d)
print(res)
0