Problem p02573 (python)

Fixed submission:
import numpy as np

class union_find:
    def __init__(self,N):
        self.r = np.ones(N)*-1
    
    def root(self,x):
        if self.r[x]<0:
            return int(x)
        else:
            self.r[x] = self.root(int(self.r[x]))
            return int(self.r[x])
        
    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        else:
            self.r[x] += self.r[y]
            self.r[y] = int(x)
            return True
        
    def size(self,x):
        return -self.r[self.root(x)]


N,M = [int(i) for i in input().split()]

Union = union_find(N)
for i in range(M):
    x,y = [int(i) for i in input().split()]
    Union.unite(x-1,y-1)

Y = - min(Union.r)
print(int(Y))

Buggy submission (verdict: Runtime Error):
import numpy as np

class union_find:
    def __init__(self,N):
        self.r = np.ones(N)*-1
    
    def root(self,x):
        if self.r[x]<0:
            return int(x)
        else:
            self.r[x] = self.root(int(self.r[x]))
            return int(self.r[x])
        
    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        else:
            self.r[x] += self.r[y]
            self.r[y] = int(x)
            return True
        
    def size(self,x):
        return -self.r[self.root(x)]


N,M = [int(i) for i in input().split()]

Union = union_find(N)
for i in range(M):
    x,y = [int(i) for i in input().split()]
    Union.unite(x-1,y-1)

Y = 0
for i in range(N):
    Y = max(Y,Union.size(i))
print(int(Y))

Buggy submission (verdict: Runtime Error):
import numpy as np

class union_find:
    def __init__(self,N):
        self.r = np.ones(N)*-1
    
    def root(self,x):
        if self.r[x]<0:
            return int(x)
        else:
            self.r[x] = self.root(int(self.r[x]))
            return int(self.r[x])
        
    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        else:
            self.r[x] += self.r[y]
            self.r[y] = int(x)
            return True
        
    def size(self,x):
        return -self.r[self.root(x)]


N,M = [int(i) for i in input().split()]

Union = union_find(N)
for i in range(M):
    x,y = [int(i) for i in input().split()]
    Union.unite(x,y)

Y = 0
for i in range(N):
    Y = max(Y,Union.size(i))
print(int(Y))

Buggy submission (verdict: Runtime Error):
import numpy as np

n,M = [int(i) for i in input().split()]

N = np.ones(n)*-1
n_group = 0

for i in range(M):
    a,b = [int(i) for i in input().split()]
    
    if N[a]==-1 and N[b]==-1:
        N[a] = n_group
        N[b] = n_group
        n_group += 1
    
    elif N[a]>-1 and N[b]>-1:
        new = min(N[a],N[b])
        old = max(N[a],N[b])
        for i in range(n):
            if N[i] == old:
                N[i] = new
    else:
        if N[a]>-1:
            N[b] = N[a]
        else:
            N[a] = N[b]
Y = 0
for i in range(n_group):
    Y = max(sum(N==i),Y)
print(Y)

Buggy submission (verdict: Runtime Error):
import numpy as np

n,M = [int(i) for i in input().split()]

N = np.ones(n)*-1
n_group = 0

for i in range(M):
    a,b = [int(i) for i in input().split()]
    
    if N[a]==-1 and N[b]==-1:
        N[a] = n_group
        N[b] = n_group
        n_group += 1
    
    elif N[a]>-1 and N[b]>-1:
        new = min(N[a],N[b])
        old = max(N[a],N[b])
        for i in range(n):
            if N[i] == old:
                N[i] = new
    else:
        if N[a]>-1:
            N[b] = N[a]
        else:
            N[a] = N[b]
Y = 0
for i in range(n_group):
    Y = max(sum(N==i+1),Y)
print(Y)

Buggy submission (verdict: Runtime Error):
N,M = [int(i) for i in input().split()]

relations = []
for i in range(M):
    relations.append({int(i) for i in input().split()})
    

def search(node,stock):
    
    n_member = 0
    
    while(len(node)>0):
        n_member += len(node)
        go_list = []
        ng_list = []
        
        for s in stock:
            if len(s & node)>0:
                go_list = np.append(go_list,list(s))
            else:
                ng_list.append(s)
        node = set(np.unique(go_list)) - node
        stock = ng_list
            
    return n_member,stock
    
    
MaxMember = 1    
while(len(relations)>1):
    l_member,relations = search(relations[0],relations[1:])
    MaxMember = max(MaxMember,l_member)

print(MaxMember)

Buggy submission (verdict: Runtime Error):
N,M = [int(i) for i in input().split()]

groups = []

for i in range(M):
    a,b = [int(i) for i in input().split()]
    flag = True
    for j,g in enumerate(groups):
        if a in g or b in g:
            groups[j] = np.unique(np.append(g,[a,b]))
            flag = False
    if flag:
        groups.append([a,b])
        

maxMember = 0
for g in groups:
    maxMember = max(maxMember,len(g))

print(maxMember)