結果
問題 | No.2072 Anatomy |
ユーザー |
![]() |
提出日時 | 2023-01-27 22:45:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 614 ms / 2,000 ms |
コード長 | 1,252 bytes |
コンパイル時間 | 449 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 90,000 KB |
最終ジャッジ日時 | 2024-06-28 07:43:32 |
合計ジャッジ時間 | 10,608 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
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))