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):
def uf_find(x):
  z = x
  while z != p[z]:
    z = p[z]
  p[x] = z
  return z

def uf_unite(x,y):
  global rand
  x = uf_find(x)
  y = uf_find(y)
  if x != y:
    rand += 1
    if rand % 2 ==0:
      p[y] = x
    else:
      p[x] = y

N, M = map(int, input().split())
p = list(range(N))
rand = 0

for i in range(M):
  A, B = [int(j)-1 for j in input().split()]
  uf_unite(A,B)
  print(p)
  
for i in range(N):
  p[i] = uf_find(i)
print(p)

q = [0]*N
for i in range(N):
  q[i] = p.count(i)
  
print(max(q))


import sys
sys.setrecursionlimit(10**7)

def uf_find(x):
  if x == p[x]:
    return x
  else:
    p[x] = uf_find(p[x])
    return p[x]

def uf_unite(x,y):
  x = uf_find(x)
  y = uf_find(y)
  if x != y:
    if r[y]>r[x]:
      x,y = y,x
    if r[x]==r[y]:
      r[x]+= 1
    p[y] = x
    #print(r)


N, M = map(int, input().split())
p = list(range(N))
r = [0]*N

for i in range(M):
  A, B = [int(j)-1 for j in input().split()]
  uf_unite(A,B)
  print(p)
  
for i in range(N):
  p[i] = uf_find(i)

q = [0]*N
for i in range(N):
  q[i] = p.count(i)
  
print(max(q))


def uf_find(x):
  while x != p[x]:
    x = p[x]
    print(x)
  return(x)

def uf_unite(x,y):
  x = uf_find(x)
  y = uf_find(y)
  if x == y:
    pass
  else:
    p[x] = y

N, M = map(int, input().split())
p = list(range(N))

for i in range(M):
  A, B = [int(i)-1 for i in input().split()]
  uf_unite(A,B)
  #print(p)

for i in range(N):
  p[i] = uf_find(i)
print(p)

q = [0]*N
for i in range(N):
  q[i] = p.count(i)
  
print(max(q))


def uf_find(x):
  if p[x] == -1:
    return x
  else:
    for i in range(5):
      x = p[x]
      if x == -1:
        return x
    return x

def uf_unite(x,y):
  x = uf_find(x)
  y = uf_find(y)
  if x == y and x != -1:
    pass
  else:
    p[x] = y

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

for i in range(M):
  A, B = [int(i)-1 for i in input().split()]
  uf_unite(A,B)
  #print(p)

for i in range(N):
  p[i] = uf_find(i)
print(p)

q = [0]*N
for i in range(N):
  q[i] = p.count(i)
  
print(max(q))
  

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

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

def find(x):
  if par[x] == x:
    return x
  else:
    return find(par[x])
  
def unite(x,y):
  x = find(x)
  y = find(y)
  
  if x == y:
    return
  if rank[x]<rank[y]:
    x,y = y,x
  else:
  par[y] = x
  size[x] += size[y]
  if rank[x]==rank[y]:
    rank[x]+=1
    
for i in range(M):
  a,b = [int(i)-1 for i in input().split()]
  unite(a,b)
  
print(max(size))

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

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

def find(x):
  if par[x] == x:
    return x
  else:
    return find(par[x])
  
def unite(x,y):
  x = find(x)
  y = find(y)
  
  if x == y:
    return
  if rank[x]<rank[y]:
    x,y = y,x
  par[y] = x
  size[x] += size[y]
  if rank[x]==rank[y]:
    rank[x]+=1
    
for i in range(M):
  a,b = [int(i)-1 for i in input().split()]
  unite(a,b)
  
print(max(size))

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Accepted