結果
問題 | No.2072 Anatomy |
ユーザー | rlangevin |
提出日時 | 2023-01-27 22:45:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 646 ms / 2,000 ms |
コード長 | 1,252 bytes |
コンパイル時間 | 527 ms |
コンパイル使用メモリ | 87,092 KB |
実行使用メモリ | 93,636 KB |
最終ジャッジ日時 | 2023-09-10 16:33:15 |
合計ジャッジ時間 | 13,283 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
71,284 KB |
testcase_01 | AC | 75 ms
71,376 KB |
testcase_02 | AC | 83 ms
75,440 KB |
testcase_03 | AC | 84 ms
75,376 KB |
testcase_04 | AC | 80 ms
75,616 KB |
testcase_05 | AC | 81 ms
75,496 KB |
testcase_06 | AC | 83 ms
75,400 KB |
testcase_07 | AC | 84 ms
75,416 KB |
testcase_08 | AC | 637 ms
91,932 KB |
testcase_09 | AC | 239 ms
86,772 KB |
testcase_10 | AC | 485 ms
88,900 KB |
testcase_11 | AC | 349 ms
88,680 KB |
testcase_12 | AC | 294 ms
85,596 KB |
testcase_13 | AC | 509 ms
92,084 KB |
testcase_14 | AC | 441 ms
86,856 KB |
testcase_15 | AC | 221 ms
84,056 KB |
testcase_16 | AC | 517 ms
90,720 KB |
testcase_17 | AC | 297 ms
87,896 KB |
testcase_18 | AC | 218 ms
83,064 KB |
testcase_19 | AC | 496 ms
91,204 KB |
testcase_20 | AC | 646 ms
93,636 KB |
testcase_21 | AC | 225 ms
86,912 KB |
testcase_22 | AC | 504 ms
91,800 KB |
testcase_23 | AC | 231 ms
87,308 KB |
testcase_24 | AC | 220 ms
86,980 KB |
testcase_25 | AC | 482 ms
91,560 KB |
testcase_26 | AC | 75 ms
71,420 KB |
testcase_27 | AC | 230 ms
87,628 KB |
testcase_28 | AC | 446 ms
92,568 KB |
ソースコード
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 = map(int, input().split()) A, B = [0] * M, [0] * M for i in range(M): A[i], B[i] = map(int, input().split()) A.reverse() B.reverse() U = UnionFind(N) dp = [0] * N for i in range(M): a, b = A[i], B[i] a, b = a - 1, b - 1 if U.is_same(a, b): dp[U.find(a)] += 1 continue v = max(dp[U.find(a)], dp[U.find(b)]) U.union(a, b) dp[U.find(a)] = max(dp[U.find(a)], v + 1) print(max(dp))