結果
問題 | No.2072 Anatomy |
ユーザー | tassei903 |
提出日時 | 2022-09-19 13:13:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 381 ms / 2,000 ms |
コード長 | 2,106 bytes |
コンパイル時間 | 355 ms |
コンパイル使用メモリ | 82,196 KB |
実行使用メモリ | 98,948 KB |
最終ジャッジ日時 | 2024-06-01 16:13:18 |
合計ジャッジ時間 | 7,864 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,048 KB |
testcase_01 | AC | 44 ms
54,368 KB |
testcase_02 | AC | 44 ms
55,856 KB |
testcase_03 | AC | 47 ms
61,176 KB |
testcase_04 | AC | 44 ms
56,044 KB |
testcase_05 | AC | 48 ms
61,660 KB |
testcase_06 | AC | 44 ms
56,736 KB |
testcase_07 | AC | 50 ms
61,420 KB |
testcase_08 | AC | 381 ms
96,520 KB |
testcase_09 | AC | 178 ms
94,212 KB |
testcase_10 | AC | 320 ms
96,148 KB |
testcase_11 | AC | 249 ms
96,520 KB |
testcase_12 | AC | 213 ms
90,388 KB |
testcase_13 | AC | 307 ms
98,056 KB |
testcase_14 | AC | 298 ms
90,012 KB |
testcase_15 | AC | 167 ms
88,104 KB |
testcase_16 | AC | 337 ms
98,308 KB |
testcase_17 | AC | 228 ms
97,160 KB |
testcase_18 | AC | 156 ms
86,444 KB |
testcase_19 | AC | 308 ms
98,184 KB |
testcase_20 | AC | 379 ms
98,448 KB |
testcase_21 | AC | 181 ms
96,784 KB |
testcase_22 | AC | 305 ms
98,064 KB |
testcase_23 | AC | 187 ms
96,520 KB |
testcase_24 | AC | 184 ms
96,400 KB |
testcase_25 | AC | 293 ms
97,792 KB |
testcase_26 | AC | 43 ms
54,800 KB |
testcase_27 | AC | 187 ms
96,648 KB |
testcase_28 | AC | 359 ms
98,948 KB |
ソースコード
import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### from collections import defaultdict class UnionFind2(): def __init__(self, n, e, f): self.n = n self.parents = [-1] * n self.a = [e] * n self.f = f def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x self.a[x] = self.f(self.a[x], self.a[y]) self.a[y] = e def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) e = 0 def f(x, y): return max(x, y) + 1 n, m = na() E = [] for i in range(m): u, v = na() u-=1 v-=1 E.append((u, v)) uf = UnionFind2(n, e, f) for u, v in E[::-1]: if uf.same(u, v): uf.a[uf.find(u)] += 1 else: uf.union(u, v) print(max([uf.a[x] for x in range(n)]))