結果

問題 No.2072 Anatomy
ユーザー shobonvipshobonvip
提出日時 2022-09-16 22:35:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 401 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 94,016 KB
最終ジャッジ日時 2023-08-23 16:10:31
合計ジャッジ時間 8,119 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,068 KB
testcase_01 AC 69 ms
70,928 KB
testcase_02 AC 74 ms
71,268 KB
testcase_03 AC 74 ms
71,072 KB
testcase_04 AC 71 ms
71,072 KB
testcase_05 AC 75 ms
71,316 KB
testcase_06 AC 73 ms
71,284 KB
testcase_07 AC 73 ms
71,180 KB
testcase_08 AC 401 ms
90,548 KB
testcase_09 AC 214 ms
89,500 KB
testcase_10 AC 340 ms
91,948 KB
testcase_11 AC 282 ms
91,508 KB
testcase_12 AC 235 ms
88,024 KB
testcase_13 AC 321 ms
92,336 KB
testcase_14 AC 296 ms
86,492 KB
testcase_15 AC 189 ms
85,308 KB
testcase_16 AC 340 ms
92,600 KB
testcase_17 AC 250 ms
91,900 KB
testcase_18 AC 176 ms
85,392 KB
testcase_19 AC 318 ms
92,568 KB
testcase_20 AC 381 ms
93,760 KB
testcase_21 AC 218 ms
91,624 KB
testcase_22 AC 334 ms
94,016 KB
testcase_23 AC 217 ms
91,540 KB
testcase_24 AC 214 ms
91,564 KB
testcase_25 AC 303 ms
92,324 KB
testcase_26 AC 71 ms
71,120 KB
testcase_27 AC 219 ms
91,412 KB
testcase_28 AC 369 ms
93,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFindWithDp:
	def __init__(self, n):
		self.n = n
		self.dp = [0] * n
		self.parents = [-1] * n
	
	def find(self, x):
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]
	
	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			self.dp[x] += 1
			return
		if self.parents[x] > self.parents[y]:
			x, y = y, x
		self.parents[x] += self.parents[y]
		self.dp[x] = max(self.dp[x], self.dp[y]) + 1
		self.parents[y] = x

n, m = map(int,input().split())
edges = []
for i in range(m):
	u, v = map(int,input().split())
	u -= 1
	v -= 1
	edges.append((u, v))

uf = UnionFindWithDp(n)
for i in range(m-1,-1,-1):
	u, v = edges[i]
	uf.union(u, v)

ans = 0
for i in range(n):
	ans = max(ans, uf.dp[i])
print(ans)
0