結果
問題 | No.1690 Power Grid |
ユーザー | asumo0729 |
提出日時 | 2021-09-24 23:38:45 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,629 bytes |
コンパイル時間 | 209 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 77,696 KB |
最終ジャッジ日時 | 2024-07-05 11:36:28 |
合計ジャッジ時間 | 3,910 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
54,016 KB |
testcase_01 | AC | 47 ms
54,784 KB |
testcase_02 | AC | 43 ms
54,912 KB |
testcase_03 | AC | 43 ms
54,528 KB |
testcase_04 | AC | 42 ms
54,912 KB |
testcase_05 | AC | 47 ms
54,528 KB |
testcase_06 | AC | 205 ms
76,160 KB |
testcase_07 | AC | 202 ms
76,544 KB |
testcase_08 | AC | 203 ms
76,696 KB |
testcase_09 | AC | 207 ms
76,416 KB |
testcase_10 | AC | 66 ms
69,760 KB |
testcase_11 | AC | 64 ms
68,864 KB |
testcase_12 | AC | 43 ms
54,656 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 235 ms
76,924 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 60 ms
67,584 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 43 ms
54,528 KB |
ソースコード
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 adj = [] for i in range(N - 1): for j in range(i + 1, N): adj.append((edges[i][j], i, j)) adj.sort() citys = [i for i in range(N)] ans = inf for v in combinations(citys,K): temp = 0 candidate = [0 for _ in range(N)] build = [0 for _ in range(N)] for city in v: temp += A[city] candidate[city] = 1 build[city] = 1 for cost, x, y in adj: if candidate[x] == 1 and candidate[y] == 1: if build[x] == 0 and build[y] == 0: continue if build[x] == 1 or build[y] == 1: build[x] &= 0 build[y] &= 0 temp += cost ans = min(ans, temp) print(ans)