結果
問題 | No.1690 Power Grid |
ユーザー | asumo0729 |
提出日時 | 2021-09-24 23:33:36 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,556 bytes |
コンパイル時間 | 190 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 77,440 KB |
最終ジャッジ日時 | 2024-07-05 11:35:42 |
合計ジャッジ時間 | 3,944 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,272 KB |
testcase_01 | AC | 42 ms
54,144 KB |
testcase_02 | AC | 42 ms
55,040 KB |
testcase_03 | AC | 42 ms
54,144 KB |
testcase_04 | AC | 41 ms
54,400 KB |
testcase_05 | AC | 40 ms
54,784 KB |
testcase_06 | AC | 194 ms
76,672 KB |
testcase_07 | AC | 194 ms
76,416 KB |
testcase_08 | AC | 191 ms
76,160 KB |
testcase_09 | AC | 197 ms
76,416 KB |
testcase_10 | AC | 68 ms
69,504 KB |
testcase_11 | AC | 65 ms
68,864 KB |
testcase_12 | AC | 42 ms
54,656 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 221 ms
77,440 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 62 ms
67,584 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 41 ms
54,400 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] == 1 or build[y] == 1: build[x] &= 0 build[y] &= 0 temp += cost ans = min(ans, temp) print(ans)