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 collections as col
from collections import defaultdict as dd

d=dd(list)

N,M=map(int, input().split())
p=[-1]*N
cnt=[0]*N

for _ in range(M):
    i,j=map(int, input().split())
    if i>j:
        i,j=j,i
    d[i].append(j)

for i in d:
    for j in d[i]:
        print(i,j)
        if p[j-1]!=-1:
            if p[i-1]==-1:
                p[i-1]=j
                cnt[p[j-1]]+=1
            continue
        if p[i-1]==-1:
            p[j-1]=i
            cnt[i]+=1
        else:
            p[j-1]=p[i-1]
            cnt[p[i-1]]+=1

cnt.sort(reverse=True)
print(cnt[0]+1)

import numpy as np
from collections import deque
from collections import defaultdict as dd
import sys
sys.setrecursionlimit(10**8)

def DFS():
    temp=q.pop()

    for i in range(len(d[temp])):
        if chk[d[temp][i]-1]==0:
            chk[d[temp][i]-1]=1
            q.append(d[temp][i])
        else:break

        if d[temp][i] not in d[temp]:
            d[temp].append(d[temp][i])

    if len(q)>0:
        DFS()
    else:
        f=0
        for i in range(N):
            if chk[i]==0:
                f=1
                chk[i]=1
                q.append(i+1)
                break

        if f==0:
            ans()
        else:
            DFS()
    return

def ans():
    a=0
    for i in range(len(d)):
       a=max(a,len(d[i])+1)
    print(a) 
    exit(0)
    
    return


q=[]
d=dd(list)
N,M=map(int, input().split())
chk=np.zeros(N,dtype=np.int)

for _ in range(M):
    i,j=map(int, input().split())
    if i>j:
        i,j=j,i

    if j not in d[i]:
        d[i].append(j)
    if i not in d[j]:
        d[j].append(i)

q.append(1)
chk[0]=1

DFS()


from collections import defaultdict as dd
from collections import deque
import collections as col
d=dd(list)
q=deque([])

N,M=map(int, input().split())
for _ in range(M):
    f=0
    i,j=map(int, input().split())
    if i>j:
        i,j=j,i
    d[i].append(j)
chk=[0]*N
chk[0]=1
temp=1
a=0
while a<N:
    for i in range(len(d[temp])):
        if chk[d[temp][i]-1]==0:
            chk[d[temp][i]-1]=1
            for j in range(len(d[d[temp][i]])):
                chk[d[d[temp][i]][j]-1]=1
                d[temp].append(d[d[temp][i]][j])
                q.append(d[d[temp][i]][j])

    if len(q)>0:
        temp=q.pop()
    if chk[temp-1]==0:
        continue

    else:
        while a<N:
            if chk[a]==0:
                chk[a]=1
                temp=a+1
                break
            a+=1
print(d)
ans=0
for i in  range(N):
    ans=max(ans,len(col.Counter(d[i]))+1)
print(ans)

import numpy as np
from collections import deque
from collections import defaultdict as dd
import collections as col
import sys
sys.setrecursionlimit(10**8)

def DFS():
    temp=q.pop()

    for i in range(len(d[temp])):
        if chk[d[temp][i]-1]==0:
            chk[d[temp][i]-1]=1
            q.append(d[temp][i])
        else:break

        if d[temp][i] not in d[temp]:
            d[temp].append(d[temp][i])

    if len(q)>0:
        DFS()
    else:
        f=0
        for i in range(N):
            if chk[i]==0:
                f=1
                chk[i]=1
                q.append(i+1)
                break

        if f==0:
            ans()
        else:
            DFS()
    return

def ans():
    ans=0
    for i in d:
        if len(d[i])>0:
            ans=max(ans,len(col.Counter(d[i]))+1)
    print(ans)
    exit(0)

    return


q=[]
d=dd(list)
N,M=map(int, input().split())
chk=np.zeros(N,dtype=np.int)

for _ in range(M):
    i,j=map(int, input().split())
    if i>j:
        i,j=j,i
    d[i].append(j)

q.append(1)
chk[0]=1

DFS()

from collections import defaultdict as dd
from collections import deque
import collections as col
d=dd(list)
q=deque([])

N,M=map(int, input().split())
for _ in range(M):
    f=0
    i,j=map(int, input().split())
    if i>j:
        i,j=j,i
    d[i].append(j)
chk=[0]*N
chk[0]=1
temp=1
a=0
while a<N:
    for i in range(len(d[temp])):
        for j in range(len(d[d[temp][i]])):
            chk[d[d[temp][i]][j]-1]=1
            d[temp].append(d[d[temp][i]][j])
            q.append(d[d[temp][i]][j])

    if len(q)==0:
        while a<N:
            if chk[a]==0:
                chk[a]=1
                temp=a+1
                break
            a+=1
    else:
        temp=q.pop()
print(d)
ans=0
for i in  range(N):
    ans=max(ans,len(col.Counter(d[i]))+1)
print(ans)

from collections import defaultdict as dd
from collections import deque
import collections as col
d=dd(list)
q=deque([])

N,M=map(int, input().split())
for _ in range(M):
    i,j=map(int, input().split())
    if i>j:
        i,j=j,i
    f=0
    for a in range(i):
        if i in d[a]:
            f=1
            d[a].append(j)
            break
            
    if f==1:continue
    else:d[i].append(j)



print(d)
ans=0
for i in  range(N):
    if len(d[i])>0:
        ans=max(ans,len(col.Counter(d[i]))+1)
print(ans)

import sys
sys.setrecursionlimit(10**8)

def find(x):
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def union(a,b):
    a=find(a)
    b=find(b)
    if a==b:
        return
    
    if rank[a]<rank[b]:
        par[a]=b
        rank[b]+=rank[a]
        rank[a]=rank[b]
    else:
        par[b]=a
        rank[a]+=rank[b]
        rank[b]=rank[a]

    return

def chk(a,b):
    if par[a]==par[b]:
        print('Yes')
    else:
        print('No')

    return

N,M=map(int, input().split())

par=(list(range(N+1)))
rank=[1]*(N+1)

for _ in range(M):
    A,B=map(int, input().split())
    union(A,B)

print(max(rank))

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted