結果

問題 No.2072 Anatomy
ユーザー ニックネームニックネーム
提出日時 2022-09-16 21:46:11
言語 Python3
(3.10.1 + numpy 1.22.3 + scipy 1.8.0)
結果
AC  
実行時間 914 ms / 2,000 ms
コード長 634 bytes
コンパイル時間 330 ms
使用メモリ 45,612 KB
最終ジャッジ日時 2023-01-11 06:28:11
合計ジャッジ時間 18,957 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 15 ms
7,632 KB
testcase_01 AC 15 ms
7,768 KB
testcase_02 AC 17 ms
7,980 KB
testcase_03 AC 16 ms
7,892 KB
testcase_04 AC 16 ms
7,740 KB
testcase_05 AC 16 ms
7,812 KB
testcase_06 AC 16 ms
8,032 KB
testcase_07 AC 17 ms
7,808 KB
testcase_08 AC 801 ms
37,596 KB
testcase_09 AC 802 ms
36,988 KB
testcase_10 AC 896 ms
37,344 KB
testcase_11 AC 864 ms
38,228 KB
testcase_12 AC 717 ms
31,512 KB
testcase_13 AC 899 ms
41,656 KB
testcase_14 AC 599 ms
28,780 KB
testcase_15 AC 531 ms
27,068 KB
testcase_16 AC 894 ms
40,740 KB
testcase_17 AC 852 ms
38,248 KB
testcase_18 AC 458 ms
24,168 KB
testcase_19 AC 901 ms
42,556 KB
testcase_20 AC 913 ms
42,532 KB
testcase_21 AC 840 ms
45,612 KB
testcase_22 AC 903 ms
41,680 KB
testcase_23 AC 886 ms
39,072 KB
testcase_24 AC 823 ms
45,480 KB
testcase_25 AC 914 ms
42,596 KB
testcase_26 AC 15 ms
7,704 KB
testcase_27 AC 892 ms
38,992 KB
testcase_28 AC 851 ms
42,256 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