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):
N,M = map(int,input().split())
hint_list = [list(map(int,input().split())) for i in range(M)]
friend_list = []

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

hint_list = get_unique_list(hint_list)

if M == 0:
    print(N)
else:
    friend_list.append(hint_list[0])
    for i in range(1,len(hint_list)):
        for j in range(len(friend_list)):
            if hint_list[i][0] in friend_list[j]:
                if hint_list[i][1] in friend_list[j]:
                    pass
                else:
                    frined_list[j].append(hint_list[i][1])
            elif hint_list[i][1] in friend_list[j]:
                if hint_list[i][0] in friend_list[j]:
                    pass
                else:
                    frined_list[j].append(hint_list[i][0])
            else:
                pass

    friend_length = []

    for i in range(len(friend_list)):
        friend_length.append(len(friend_list[i]))

    print(max(friend_length))

from collections import deque

N,M = map(int,input().split())
hint_list = [list(map(int,input().split())) for i in range(M)]
friend_list = []

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

hint_list = get_unique_list(hint_list)

if M == 0:
    print(N)
else:
    for i in range(1,N+1):
        i_list = []
        j_list = []
        for j in range(len(hint_list)):
            if i in hint_list[j]:
                i_list.append(hint_list[j])
                j_list.append(j)
            else:
                pass
            
        i_list = list(set(sum(i_list,[])))
        if i_list != []:
            new_j_list = []
            for i in range(len(j_list)):
                new_j_list.append(j_list[i]-i)
            for i in range(len(new_j_list)):
                del hint_list[new_j_list[i]]
            hint_list.append(i_list)
        else:
            pass
        print(hint_list)
    
    friend_len = []
    for i in range(len(hint_list)):
        friend_len.append(len(hint_list[i]))
    
    print(max(friend_len))

from collections import deque

N,M = map(int,input().split())
hint_list = [list(map(int,input().split())) for i in range(M)]
friend_list = []

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

hint_list = get_unique_list(hint_list)

if M == 0:
    print(0)
else:
    for i in range(1,N+1):
        i_list = []
        j_list = []
        for j in range(len(hint_list)):
            if i in hint_list[j]:
                i_list.append(hint_list[j])
                j_list.append(j)
            else:
                pass
            
        i_list = list(set(sum(i_list,[])))
        if i_list != []:
            new_j_list = []
            for i in range(len(j_list)):
                new_j_list.append(j_list[i]-i)
            for i in range(len(new_j_list)):
                del hint_list[new_j_list[i]]
            hint_list.append(i_list)
        else:
            pass
    
    friend_len = []
    print(hint_list)
    for i in range(len(hint_list)):
        friend_len.append(len(hint_list[i]))
    
    print(max(friend_len))

N,M = map(int,input().split())
hint_list = [list(map(int,input().split())) for i in range(M)]
friend_list = []

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

hint_list = get_unique_list(hint_list)

if M == 0:
    print(N)
else:
    friend_list.append(hint_list[0])
    for i in range(1,len(hint_list)):
        for j in range(len(friend_list)):
            if hint_list[i][0] in friend_list[j]:
                if hint_list[i][1] in friend_list[j]:
                    pass
                else:
                    frined_list[j].append(hint_list[i][1])
            elif hint_list[i][1] in friend_list[j]:
                if hint_list[i][0] in friend_list[j]:
                    pass
                else:
                    frined_list[j].append(hint_list[i][0])
            else:
                pass

    friend_length = []

    for i in range(len(friend_list)):
        friend_length.append(len(friend_list[i]))

print(max(friend_length))

from collections import deque
 
N,M = map(int,input().split())
hint_list = [list(map(int,input().split())) for i in range(M)]

r = [-1] * N

def find(a):
    if r[a] < 0:
        return a
    else:
        if r[r[a]] < 0:
            return r[a]
        else:
            r[a] =r[r[a]]
            return r[a]
    
def union(a,b):
    a -= 1
    b -= 1
    ar = find(a)
    br = find(b)
    if ar == br:
        return
    else:
        if r[ar] > r[br]:
            ar,br = br,ar
        r[ar] += r[br]
        r[br] = ar
        return
        
for i in range(len(hint_list)):
    union(hint_list[i][0],hint_list[i][1])
    print(r)
    
print(-min(r))

from collections import deque
 
N,M = map(int,input().split())
hint_list = [list(map(int,input().split())) for i in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x -= 1
        y -= 1
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

uf = UnionFind(N)
for i in range(len(hint_list)):
    uf.union(hint_list[i][0],hint_list[i][1])
    
print(-min(uf.parents))

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Accepted