結果

問題 No.2072 Anatomy
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-09-16 22:06:34
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 855 ms / 2,000 ms
コード長 994 bytes
コンパイル時間 316 ms
使用メモリ 122,240 KB
最終ジャッジ日時 2023-01-11 07:08:27
合計ジャッジ時間 19,143 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 286 ms
93,788 KB
testcase_01 AC 285 ms
93,600 KB
testcase_02 AC 294 ms
93,640 KB
testcase_03 AC 302 ms
93,860 KB
testcase_04 AC 291 ms
93,624 KB
testcase_05 AC 298 ms
93,744 KB
testcase_06 AC 293 ms
93,676 KB
testcase_07 AC 298 ms
93,868 KB
testcase_08 AC 835 ms
119,084 KB
testcase_09 AC 616 ms
116,344 KB
testcase_10 AC 768 ms
117,728 KB
testcase_11 AC 705 ms
118,228 KB
testcase_12 AC 624 ms
113,028 KB
testcase_13 AC 751 ms
118,468 KB
testcase_14 AC 694 ms
112,396 KB
testcase_15 AC 539 ms
109,396 KB
testcase_16 AC 779 ms
119,192 KB
testcase_17 AC 672 ms
117,988 KB
testcase_18 AC 511 ms
107,676 KB
testcase_19 AC 755 ms
120,124 KB
testcase_20 AC 855 ms
122,240 KB
testcase_21 AC 625 ms
118,448 KB
testcase_22 AC 764 ms
119,704 KB
testcase_23 AC 640 ms
118,344 KB
testcase_24 AC 631 ms
118,324 KB
testcase_25 AC 725 ms
118,908 KB
testcase_26 AC 294 ms
93,820 KB
testcase_27 AC 637 ms
118,332 KB
testcase_28 AC 795 ms
120,160 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