結果

問題 No.2072 Anatomy
ユーザー shobonvipshobonvip
提出日時 2022-09-16 22:35:41
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 578 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 294 ms
使用メモリ 105,828 KB
最終ジャッジ日時 2023-01-11 07:50:29
合計ジャッジ時間 12,970 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 83 ms
75,544 KB
testcase_01 AC 81 ms
75,736 KB
testcase_02 AC 89 ms
75,736 KB
testcase_03 AC 89 ms
75,796 KB
testcase_04 AC 86 ms
75,724 KB
testcase_05 AC 89 ms
75,476 KB
testcase_06 AC 89 ms
75,756 KB
testcase_07 AC 92 ms
75,500 KB
testcase_08 AC 572 ms
102,184 KB
testcase_09 AC 374 ms
101,200 KB
testcase_10 AC 518 ms
103,488 KB
testcase_11 AC 449 ms
103,168 KB
testcase_12 AC 373 ms
98,640 KB
testcase_13 AC 491 ms
104,284 KB
testcase_14 AC 449 ms
95,988 KB
testcase_15 AC 312 ms
95,260 KB
testcase_16 AC 526 ms
104,868 KB
testcase_17 AC 428 ms
103,740 KB
testcase_18 AC 293 ms
93,460 KB
testcase_19 AC 508 ms
104,840 KB
testcase_20 AC 578 ms
105,828 KB
testcase_21 AC 388 ms
103,856 KB
testcase_22 AC 507 ms
104,576 KB
testcase_23 AC 390 ms
103,668 KB
testcase_24 AC 396 ms
103,832 KB
testcase_25 AC 474 ms
104,620 KB
testcase_26 AC 81 ms
75,704 KB
testcase_27 AC 392 ms
103,752 KB
testcase_28 AC 554 ms
105,232 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