結果

問題 No.2072 Anatomy
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-09-16 22:06:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 583 ms / 2,000 ms
コード長 994 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 109,292 KB
最終ジャッジ日時 2023-08-23 15:40:26
合計ジャッジ時間 13,088 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 183 ms
79,488 KB
testcase_01 AC 184 ms
79,612 KB
testcase_02 AC 185 ms
79,344 KB
testcase_03 AC 188 ms
79,232 KB
testcase_04 AC 184 ms
79,604 KB
testcase_05 AC 186 ms
79,196 KB
testcase_06 AC 188 ms
79,416 KB
testcase_07 AC 189 ms
79,968 KB
testcase_08 AC 583 ms
105,652 KB
testcase_09 AC 386 ms
104,128 KB
testcase_10 AC 521 ms
105,320 KB
testcase_11 AC 449 ms
105,172 KB
testcase_12 AC 397 ms
100,512 KB
testcase_13 AC 494 ms
105,764 KB
testcase_14 AC 468 ms
98,832 KB
testcase_15 AC 340 ms
96,724 KB
testcase_16 AC 515 ms
106,204 KB
testcase_17 AC 430 ms
105,292 KB
testcase_18 AC 327 ms
94,828 KB
testcase_19 AC 496 ms
107,276 KB
testcase_20 AC 571 ms
107,892 KB
testcase_21 AC 397 ms
105,620 KB
testcase_22 AC 503 ms
107,028 KB
testcase_23 AC 395 ms
106,172 KB
testcase_24 AC 394 ms
105,840 KB
testcase_25 AC 476 ms
106,548 KB
testcase_26 AC 186 ms
79,436 KB
testcase_27 AC 394 ms
106,060 KB
testcase_28 AC 536 ms
109,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from ctypes import Union


class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
        self.score = [0]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            self.score[self.find(x)] += 1
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.score[x] = max(self.score[x],self.score[y])+1
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

n,m = map(int,input().split())
Edges = [[int(x)-1 for x in input().split()] for i in range(m)]

uf = Unionfind(n)

for u,v in Edges[::-1]:
    uf.union(u,v)
    # print(uf.score)

print(max(uf.score))
0