結果

問題 No.2072 Anatomy
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-09-16 21:58:54
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 607 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 244 ms
使用メモリ 107,920 KB
最終ジャッジ日時 2023-01-11 06:51:35
合計ジャッジ時間 11,510 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 71 ms
75,596 KB
testcase_01 AC 71 ms
75,852 KB
testcase_02 AC 76 ms
75,824 KB
testcase_03 AC 78 ms
75,840 KB
testcase_04 AC 75 ms
75,600 KB
testcase_05 AC 79 ms
75,856 KB
testcase_06 AC 76 ms
75,960 KB
testcase_07 AC 80 ms
75,516 KB
testcase_08 AC 601 ms
106,180 KB
testcase_09 AC 339 ms
102,752 KB
testcase_10 AC 509 ms
104,288 KB
testcase_11 AC 423 ms
104,920 KB
testcase_12 AC 349 ms
99,500 KB
testcase_13 AC 524 ms
106,848 KB
testcase_14 AC 471 ms
97,820 KB
testcase_15 AC 274 ms
96,232 KB
testcase_16 AC 531 ms
106,336 KB
testcase_17 AC 377 ms
105,160 KB
testcase_18 AC 255 ms
94,332 KB
testcase_19 AC 521 ms
107,168 KB
testcase_20 AC 607 ms
107,920 KB
testcase_21 AC 349 ms
105,472 KB
testcase_22 AC 526 ms
106,748 KB
testcase_23 AC 346 ms
105,208 KB
testcase_24 AC 347 ms
105,336 KB
testcase_25 AC 515 ms
107,092 KB
testcase_26 AC 72 ms
75,804 KB
testcase_27 AC 347 ms
105,284 KB
testcase_28 AC 499 ms
107,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #




class unionfind:
    def __init__(self,uni_num):
        self.uni_num=uni_num
        self.union_root = [-1 for i in range(self.uni_num + 1)]
        self.union_depth = [0] * (self.uni_num + 1)
        self.e_num=[0]*(self.uni_num+1)

    def find(self,x):  # 親は誰?
        if self.union_root[x] < 0:
            return x
        else:
            self.union_root[x] = self.find(self.union_root[x])
            return self.union_root[x]

    def unite(self,x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            self.e_num[x]+=1
            return
        if self.union_depth[x] < self.union_depth[y]:
            x, y = y, x
        if self.union_depth[x] == self.union_depth[y]:
            self.union_depth[x] += 1
        self.union_root[x] += self.union_root[y]
        self.union_root[y] = x
        self.e_num[x]=max(self.e_num[x],self.e_num[y])+1


    def size(self,x):
        return -self.union_root[self.find(x)]

    def same(self,x,y):
        return self.find(x)==self.find(y)
    def edge(self,x):
        return self.e_num[self.find(x)]


n,m=map(int,input().split())
uf=unionfind(n+2)
e=[]
for i in range(m):
    u,v=map(int,input().split())
    e.append((u,v))
e.reverse()
for u,v in e:uf.unite(u,v)
print(uf.edge(1))
0