Q80227 - 2026编程挑战赛Python提高组27
统计题目( 单选题 )
执行完所有操作后,parent数组为:
parent = [0, 1, 2, 3, 4]
def find(x):
if parent[x] != x:
parent[x] = find(parent[x])
return parent[x]
def union(x, y):
rootX = find(x)
rootY = find(y)
if rootX != rootY:
parent[rootY] = rootX
union(0, 1)
union(1, 2)
union(3, 4)
find(2)

关注我们