結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | rlangevin |
提出日時 | 2023-07-16 13:04:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 607 ms / 2,000 ms |
コード長 | 1,334 bytes |
コンパイル時間 | 1,557 ms |
コンパイル使用メモリ | 81,532 KB |
実行使用メモリ | 100,272 KB |
最終ジャッジ日時 | 2023-10-17 14:57:57 |
合計ジャッジ時間 | 9,289 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,404 KB |
testcase_01 | AC | 38 ms
53,404 KB |
testcase_02 | AC | 38 ms
53,404 KB |
testcase_03 | AC | 38 ms
53,404 KB |
testcase_04 | AC | 38 ms
53,404 KB |
testcase_05 | AC | 38 ms
53,404 KB |
testcase_06 | AC | 38 ms
53,404 KB |
testcase_07 | AC | 39 ms
53,404 KB |
testcase_08 | AC | 39 ms
53,404 KB |
testcase_09 | AC | 39 ms
53,404 KB |
testcase_10 | AC | 38 ms
53,404 KB |
testcase_11 | AC | 39 ms
53,404 KB |
testcase_12 | AC | 39 ms
53,404 KB |
testcase_13 | AC | 119 ms
77,888 KB |
testcase_14 | AC | 181 ms
80,104 KB |
testcase_15 | AC | 124 ms
78,276 KB |
testcase_16 | AC | 281 ms
85,212 KB |
testcase_17 | AC | 503 ms
92,408 KB |
testcase_18 | AC | 607 ms
98,336 KB |
testcase_19 | AC | 553 ms
100,272 KB |
testcase_20 | AC | 473 ms
98,016 KB |
testcase_21 | AC | 591 ms
96,264 KB |
testcase_22 | AC | 38 ms
53,424 KB |
testcase_23 | AC | 37 ms
53,424 KB |
testcase_24 | AC | 38 ms
53,424 KB |
testcase_25 | AC | 380 ms
91,032 KB |
testcase_26 | AC | 572 ms
94,968 KB |
testcase_27 | AC | 540 ms
94,692 KB |
testcase_28 | AC | 300 ms
93,436 KB |
ソースコード
import sys input = sys.stdin.readline class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] N, M, K = map(int, input().split()) Edge = [] ans = 0 for i in range(M): a, b, c = map(int, input().split()) a, b = a - 1, b - 1 Edge.append((c, a, b, i)) ans += c S = set() for i in range(K): S.add(int(input()) - 1) U = UnionFind(N) for c, a, b, i in Edge: if i in S: U.union(a, b) ans -= c Edge.sort() for c, a, b, i in Edge: if U.is_same(a, b): continue ans -= c U.union(a, b) print(ans)