結果

問題 No.2072 Anatomy
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-09-16 21:58:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 482 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 97,324 KB
最終ジャッジ日時 2023-08-23 15:27:02
合計ジャッジ時間 8,955 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,068 KB
testcase_01 AC 71 ms
70,912 KB
testcase_02 AC 74 ms
71,000 KB
testcase_03 AC 76 ms
70,912 KB
testcase_04 AC 71 ms
70,624 KB
testcase_05 AC 75 ms
71,052 KB
testcase_06 AC 73 ms
70,760 KB
testcase_07 AC 75 ms
71,048 KB
testcase_08 AC 482 ms
93,360 KB
testcase_09 AC 217 ms
91,980 KB
testcase_10 AC 384 ms
93,540 KB
testcase_11 AC 297 ms
93,280 KB
testcase_12 AC 251 ms
89,188 KB
testcase_13 AC 399 ms
95,548 KB
testcase_14 AC 356 ms
86,984 KB
testcase_15 AC 194 ms
86,356 KB
testcase_16 AC 397 ms
94,692 KB
testcase_17 AC 263 ms
93,372 KB
testcase_18 AC 184 ms
86,056 KB
testcase_19 AC 391 ms
95,724 KB
testcase_20 AC 465 ms
97,324 KB
testcase_21 AC 227 ms
92,908 KB
testcase_22 AC 399 ms
95,248 KB
testcase_23 AC 226 ms
92,992 KB
testcase_24 AC 224 ms
92,980 KB
testcase_25 AC 383 ms
95,336 KB
testcase_26 AC 70 ms
71,052 KB
testcase_27 AC 225 ms
92,772 KB
testcase_28 AC 366 ms
96,344 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