結果
問題 | No.2072 Anatomy |
ユーザー | tassei903 |
提出日時 | 2022-09-19 13:13:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 420 ms / 2,000 ms |
コード長 | 2,106 bytes |
コンパイル時間 | 356 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 98,820 KB |
最終ジャッジ日時 | 2024-12-22 02:26:10 |
合計ジャッジ時間 | 8,505 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
54,016 KB |
testcase_01 | AC | 49 ms
54,144 KB |
testcase_02 | AC | 51 ms
54,912 KB |
testcase_03 | AC | 57 ms
60,800 KB |
testcase_04 | AC | 49 ms
54,912 KB |
testcase_05 | AC | 56 ms
60,288 KB |
testcase_06 | AC | 51 ms
55,040 KB |
testcase_07 | AC | 58 ms
61,440 KB |
testcase_08 | AC | 409 ms
95,920 KB |
testcase_09 | AC | 201 ms
94,212 KB |
testcase_10 | AC | 360 ms
95,956 KB |
testcase_11 | AC | 279 ms
96,780 KB |
testcase_12 | AC | 234 ms
90,260 KB |
testcase_13 | AC | 337 ms
98,056 KB |
testcase_14 | AC | 320 ms
89,504 KB |
testcase_15 | AC | 186 ms
87,968 KB |
testcase_16 | AC | 364 ms
98,308 KB |
testcase_17 | AC | 254 ms
96,900 KB |
testcase_18 | AC | 189 ms
86,436 KB |
testcase_19 | AC | 347 ms
97,932 KB |
testcase_20 | AC | 420 ms
98,576 KB |
testcase_21 | AC | 203 ms
96,652 KB |
testcase_22 | AC | 345 ms
98,056 KB |
testcase_23 | AC | 206 ms
96,272 KB |
testcase_24 | AC | 199 ms
96,324 KB |
testcase_25 | AC | 320 ms
98,052 KB |
testcase_26 | AC | 49 ms
54,144 KB |
testcase_27 | AC | 212 ms
96,268 KB |
testcase_28 | AC | 378 ms
98,820 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)]))