結果

問題 No.2072 Anatomy
ユーザー ニックネームニックネーム
提出日時 2022-09-16 21:46:11
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 817 ms / 2,000 ms
コード長 634 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 45,924 KB
最終ジャッジ日時 2023-08-23 14:47:35
合計ジャッジ時間 16,400 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,820 KB
testcase_01 AC 15 ms
7,852 KB
testcase_02 AC 16 ms
7,840 KB
testcase_03 AC 17 ms
7,852 KB
testcase_04 AC 17 ms
7,900 KB
testcase_05 AC 16 ms
7,972 KB
testcase_06 AC 16 ms
7,812 KB
testcase_07 AC 17 ms
7,960 KB
testcase_08 AC 697 ms
38,032 KB
testcase_09 AC 689 ms
37,560 KB
testcase_10 AC 723 ms
37,644 KB
testcase_11 AC 715 ms
38,512 KB
testcase_12 AC 562 ms
31,948 KB
testcase_13 AC 777 ms
41,924 KB
testcase_14 AC 515 ms
28,976 KB
testcase_15 AC 443 ms
27,300 KB
testcase_16 AC 774 ms
41,080 KB
testcase_17 AC 718 ms
38,516 KB
testcase_18 AC 384 ms
24,388 KB
testcase_19 AC 807 ms
42,612 KB
testcase_20 AC 817 ms
42,640 KB
testcase_21 AC 726 ms
45,924 KB
testcase_22 AC 797 ms
41,992 KB
testcase_23 AC 752 ms
39,492 KB
testcase_24 AC 741 ms
45,844 KB
testcase_25 AC 805 ms
43,012 KB
testcase_26 AC 16 ms
7,840 KB
testcase_27 AC 741 ms
39,584 KB
testcase_28 AC 701 ms
42,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)])
0