結果
| 問題 |
No.2072 Anatomy
|
| コンテスト | |
| ユーザー |
ニックネーム
|
| 提出日時 | 2022-09-16 21:46:11 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 916 ms / 2,000 ms |
| コード長 | 634 bytes |
| コンパイル時間 | 248 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 48,384 KB |
| 最終ジャッジ日時 | 2024-12-21 18:57:09 |
| 合計ジャッジ時間 | 17,600 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 |
ソースコード
class UF:
def __init__(self, n):
self.p = [-1]*n; self.c = [0]*n
def f(self, x):
if self.p[x] < 0: return x
else: self.p[x] = self.f(self.p[x]); return self.p[x]
def u(self, x, y):
x = self.f(x); y = self.f(y)
if -self.p[x] < -self.p[y]: x, y = y, x
self.c[x] = max(self.c[x], self.c[y])+1
if x == y: return
self.p[x] += self.p[y]; self.p[y] = x
def s(self, x, y): return self.f(x) == self.f(y)
n, m = map(int, input().split())
uv = [tuple(map(int, input().split())) for _ in range(m)]
uf = UF(n)
for u, v in uv[::-1]: uf.u(u-1, v-1)
print(uf.c[uf.f(0)])
ニックネーム