結果
問題 | No.1690 Power Grid |
ユーザー | asumo0729 |
提出日時 | 2021-09-24 23:13:24 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,715 bytes |
コンパイル時間 | 210 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 85,492 KB |
最終ジャッジ日時 | 2024-07-05 11:30:07 |
合計ジャッジ時間 | 28,087 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 42 ms
55,040 KB |
testcase_03 | AC | 41 ms
54,400 KB |
testcase_04 | AC | 41 ms
54,784 KB |
testcase_05 | WA | - |
testcase_06 | TLE | - |
testcase_07 | WA | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | TLE | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
ソースコード
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] 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)