Problem: There are N persons called Person 1 through Person N.  You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.  If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.  Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.  At least how many groups does he need to make?

Submission attempts (in order):
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)

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)

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)

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)

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))

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))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted