結果
問題 | No.1690 Power Grid |
ユーザー | mkawa2 |
提出日時 | 2022-02-28 23:54:57 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,372 bytes |
コンパイル時間 | 137 ms |
コンパイル使用メモリ | 82,020 KB |
実行使用メモリ | 77,980 KB |
最終ジャッジ日時 | 2024-07-07 03:10:08 |
合計ジャッジ時間 | 7,371 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,736 KB |
testcase_01 | AC | 46 ms
52,992 KB |
testcase_02 | AC | 39 ms
52,736 KB |
testcase_03 | AC | 39 ms
52,864 KB |
testcase_04 | AC | 32 ms
52,864 KB |
testcase_05 | AC | 31 ms
52,864 KB |
testcase_06 | AC | 458 ms
77,260 KB |
testcase_07 | AC | 472 ms
77,568 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 41 ms
61,056 KB |
testcase_11 | AC | 52 ms
68,864 KB |
testcase_12 | AC | 33 ms
52,608 KB |
testcase_13 | AC | 61 ms
72,704 KB |
testcase_14 | AC | 185 ms
77,184 KB |
testcase_15 | WA | - |
testcase_16 | AC | 745 ms
77,980 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 739 ms
77,696 KB |
testcase_20 | WA | - |
testcase_21 | AC | 41 ms
60,928 KB |
testcase_22 | AC | 399 ms
77,696 KB |
testcase_23 | AC | 42 ms
61,252 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 59 ms
70,272 KB |
testcase_27 | AC | 35 ms
52,864 KB |
ソースコード
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 class UnionFind: def __init__(self, n): self.state = [-1]*n self.size_table = [1]*n # cntはグループ数 self.cnt = n def root(self, u): stack = [] while self.state[u] >= 0: stack.append(u) u = self.state[u] for v in stack: self.state[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u = self.root(u) v = self.root(v) if u == v: return False du = -self.state[u] dv = -self.state[v] if du < dv: u, v = v, u if du == dv: self.state[u] -= 1 self.state[v] = u self.cnt -= 1 self.size_table[u] += self.size_table[v] return True # グループの要素数 def size(self, u): return self.size_table[self.root(u)] from itertools import combinations def cost(uu): res = sum(aa[u] for u in uu) ee = [] for i, u in enumerate(uu): for v in uu[:i]: ee.append((dist[u][v], u, v)) ee.sort(key=lambda x: x[0]) uf = UnionFind(n) for d, u, v in ee: if uf.same(u, v): continue uf.merge(u, v) res += d return res 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]) ans = inf for uu in combinations(range(n), k): ans = min(ans, cost(uu)) print(ans)