Question DSA-GRAPH-0044
MediumWhat is the output of this code?
parent = list(range(6))
def find(x):
while parent[x] != x:
parent[x] = parent[parent[x]]
x = parent[x]
return x
for a, b in [(0, 1), (2, 3), (1, 2), (4, 5)]:
parent[find(a)] = find(b)
print(len({find(x) for x in range(6)}))
- A.
3
- B.
2
- C.
Sign up free to see the answer and a step-by-step explanation.