You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def initialize(n):
global Arr, size
for i in range(n + 1):
Arr[i] = i
size[i] = 1
def find(i):
global Arr, size
while (Arr[i] != i):
Arr[i] = Arr[Arr[i]] # Skip one level
i = Arr[i] # Move to the new level
return i
def _union(xr, yr):
global Arr, size
if (size[xr] < size[yr]): # Make yr parent of xr
Arr[xr] = Arr[yr]
size[yr] += size[xr]
else: # Make xr parent of yr
Arr[yr] = Arr[xr]
size[xr] += size[yr]
def isCycle(adj, V):
global Arr, size
for i in range(V):
for j in range(len(adj[i])):
x = find(i) # find root of i
y = find(adj[i][j]) # find root of adj[i][j]
if (x == y):
return 1 # If same parent
_union(x, y) # Make them connect
return 0
No description provided.
The text was updated successfully, but these errors were encountered: