Problem:


Score : 400 points

Problem Statement

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?

Constraints

2 \leq N \leq 2\times 10^5

0 \leq M \leq 2\times 10^5

1\leq A_i,B_i\leq N

A_i \neq B_i

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
\vdots
A_M B_M

Output

Print the answer.

Sample Input 1

5 3
1 2
3 4
5 1

Sample Output 1

3

Dividing them into three groups such as \{1,3\}, \{2,4\}, and \{5\} achieves the goal.

Sample Input 2

4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4

Sample Output 2

4

Sample Input 3

10 4
3 1
4 1
5 9
2 6

Sample Output 3

3



Sample input:
5 3
1 2
3 4
5 1


Sample output:
3

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
d = {}
for i in range(1,N+1):
    d[i] = []
for i in range(M):
    A,B = map(int,input().split())
    d[A].append(B)
    d[B].append(A)
ans = 0
m = 0
for a in range(1,N+1):
    b = len(set(d[a]))
    if b > ans:
        ans = b
        m = a
P = d[m]
H = P.copy()
for a in P:
    H += d[a]
print(len(set(H)))

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    n, m = map(int, input().split())
    friends_mat = np.zeros((n, n))
    for i in range(m):
        a, b = map(int, input().split())
        friends_mat[a - 1][b - 1] = 1
        friends_mat[b - 1][a - 1] = 1
    print(int(max(friends_mat.sum(axis=1))+1))
    # print(friends_mat)




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())

l = []

A, B = map(int, input().split())
l.append((A, B))
for i in range(M-1):
    A, B = map(int, input().split())
    hit = None
    for tup in l:
        if A in tup or B in tup:
            if hit != None:
                hit += tuple(set(tup+(A, B)))
                hit
            else:
                hit = tuple (set(tup+(A, B)))
            l.remove(tup)
    if hit != None:
        l.append(hit)
    else:
        l.append((A, B))
ans = 0

for item in (l):
    if ans < len(item):
        ans = len(item)
print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int, input().split()) 

dic = dict((i, set()) for i in range(1,N+1))
print(dic)

for _ in range(M):
    a,b = map(int, input().split()) 
    dic[a].add(b)
    dic[b].add(a)

#print(dic)

def dfs(x:int, marked:set):
    a = set()
    a = a.union(dic[x])
    marked.add(x)
    for i in dic[x]:
        if i not in marked:
            b, marked = dfs(i, marked)
            a = a.union(b)

    return a, marked



res = 0
for i in range(1,N+1):
    a, marked = dfs(i, set())
    #print(a,marked)
    if len(a) > res:
        res = len(a)

print(res)

Submission status: Runtime Error

Solution code:
def packrel(s: str):
    x, y = map(int, s.split())
    if (x < y):
        return (x, y)
    else:
        return (y, x)


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

rels = list({packrel(input()) for i in range(M)})

unions = []
for a, b in rels:
    for u in unions:
        if a in u:
            u.add(b)
            break
        if b in u:
            u.add(a)
            break
    else:
        x = set((a, b))
        unions.append(x)

z = max(len(x) for x in unions)
print(z)

Submission status: Runtime Error

Solution code:
N, M = list(map(int, input().split()))
G = [[0]*N for i in range(N)]

for i in range(M):
    a, b = list(map(int, input().split()))

    G[a - 1][b - 1] = 1
    G[b - 1][a - 1] = 1


friend_chain = []
checked = [False]*N

for i in range(N):

    if (checked[i] == True):
        for a, chain_i in enumerate(friend_chain):

            for b, friend in enumerate(chain_i):

                if (i == friend):
                    for k in range(N):
                        if (G[i][k] == 1 and checked[k] == False):
                            friend_chain[a].append(k)
                            checked[k] = True

    else:
        checked[i] = True
        friend_chain_i = [i]

        for j in range(N):
            if (G[i][j] == 1 and checked[j] == False):
                friend_chain_i.append(j)
                checked[j] = True

        friend_chain.append(friend_chain_i)

    if (False not in checked):
        break


max_num = 0
for i in range(len(friend_chain)):
    if (len(friend_chain[i]) > max_num):
        max_num = len(friend_chain[i])

print(max_num)

Submission status: Runtime Error

Solution code:
from collections import Counter
N, M = map(int, input().split())
groups = [0] * (N + 1)
group_num_list = [[0]]
group_num = 1
for _ in range(M):
    A, B = map(int, input().split())
    if groups[A] != 0 and groups[B] != 0:
        if groups[A] != groups[B]:
            lower = min(groups[A], groups[B])
            higher = max(groups[A], groups[B])
            for i in group_num_list[higher]:
                groups[i] = lower
            tmp = group_num_list[higher]
            group_num_list[lower].extend(tmp)
            del group_num_list[higher]
    elif groups[A] != 0:
        groups[B] = groups[A]
        group_num_list[groups[A]].append(B)
    elif groups[B] != 0:
        groups[A] = groups[B]
        group_num_list[groups[B]].append(A)
    else:
        groups[A] = group_num
        groups[B] = group_num
        group_num_list.append([A, B])
        group_num += 1
counter = Counter(groups)
# print(collection)
# print(group_num_list)
if counter.most_common()[0][0] != 0:
    print(counter.most_common()[0][1])
else:
    print(counter.most_common()[1][1])

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
s= [[0] * n for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    s[a-1][b-1]=1
    s[b-1][a-1]=1
ss = np.array(s)
group, labels = connected_components(ss)
import  collections
retsu = collections.Counter(labels)
rkosuu=retsu.most_common()[0][1]

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 一番多いグループが何人か調べる
from statistics import mode
import collections

N, M = map(int, input().split())
team = [0 for i in range(N+1)]
ans = 0

for i in range(1,M+1):
    A, B = map(int, input().split())
    if team[A] != 0 or team[B] != 0:
        for j in range(1,N+1):
            if j != A and j != B:
                if (team[j] == team[A] and team[A] != 0) or (team[j] == team[B] and team[B] != 0):
                    team[j] = i
    team[A] = i
    team[B] = i
    # print(team)
# print(team)
many = mode(team)
if many == 0:
    team_C = collections.Counter(team)
    many_list = team_C.most_common()
    many = many_list[1][0]
    # print(many)
for i in range(1,N+1):
    if team[i] == many:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import numpy as np
import copy
N,M=map(int,input().split())
friend=defaultdict(list)
for _ in range(M):
    a,b=map(int,input().split())
    friend[a].append(b)
    friend[b].append(a)
friend2={i:list(set(j)) for i,j in friend.items()}
print(friend2)
for i,j in friend.items():
    j=list(set(j))
    if len(j)<=1:
        continue
    for k in range(len(j)):
        for kk in range(k+1,len(j)):
            print((j[k],j[kk]))
            friend2[j[k]].append(j[kk])
            friend2[j[kk]].append(j[k])
friendcount={i:len(set(j)) for i,j in friend2.items()}
print(friend2)
maxmax=np.max(list(friendcount.values()))+1
print(maxmax)

Submission status: Runtime Error

Solution code:
import copy
(N,M) = map(int,input().split())
l = []
if M == 0:
    print(1)

else:
    for i in range(M):
        l.append([int(x) for x in input().split()])

    mn = 0
    for i in range(M):
        for j in range(2):
            mn = max(mn,l[i][j])

    s = [0 for i in range(mn+100)]
    k = [0 for i in range(M)]
    cnt = 0
    for i in range(M):
        if s[l[i][0]-1] == 0 and s[l[i][1]-1] == 0:
            cnt += 1
            s[l[i][0]-1] = cnt
            s[l[i][1]-1] = cnt
            k[cnt-1] += 2
        elif s[l[i][0]-1] == 0 and s[l[i][1]-1] != 0:
            s[l[i][0]-1] = s[l[i][1]-1]
            k[s[l[i][1]-1]-1] += 1
        elif s[l[i][0]-1] != 0 and s[l[i][1]-1] == 0:
            s[l[i][1]-1] = s[l[i][0]-1]
            k[s[l[i][0]-1]-1] += 1
        elif s[l[i][0]-1] != s[l[i][1]-1]:
            t = copy.deepcopy(s)
            s = [t[l[i][1]-1] for x in t if x == t[l[i][0]-1]]
            k[t[l[i][1]-1]-1] += k[t[l[i][0]-1]-1]

    print(max(k))

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque
n,m = list(map(int, input().split()))

d = defaultdict(list)

for _ in range(m):
    
    a,b = list(map(int, input().split()))
    d[a].append(b)
    d[b].append(a)
    
   
def dfs(node):
    
    s = set()
    stack = deque([node])
    while stack:
        
        n = stack.popleft()
        s.add(n)
        for i in d[n]:
            if i not in s and visited[i] == 0:
                stack.append(i)
                
    return s
    

keys = list(d.keys())
m = max(keys)
visited = [0]*(m+1)
ans = 0

for key in keys:
    if visited[key] == 0:
        s = dfs(key)
        ans = max(ans,len(s))
        for i in s:
            visited[i] = 1


print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
A = [0] * M
B = [0] * M
for i in range(M):
    A[i],B[i] = map(int,input().split())
C = [set()]
C[0].add(A[0])
C[0].add(B[0])
for i in range(1,M):
    for j in range(len(C)):
        if A[i] in C[j] or B[i] in C[j]:
            C[j].add(A[i])
            C[j].add(B[i])
        else:
            C.append({A[i],B[i]})
ans = 0
for j in range(len(C)):
    if len(C[j]) > ans:
        ans = len(C[j])
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n, m = map(int, input().split())
index = 1
group = [0] * (n + 1) # 何番目のグループにいるか
for i in range(m):
  a, b = map(int, input().split())
  _a = group[a]
  _b = group[b]
  if _a == 0 and _b == 0: # 新しいグループ
    group[a] = index
    group[b] = index
    index += 1
  elif _a == 0: # aが新人
    group[a] = _b
  elif _b == 0: # bが新人
    group[b] = _a
  elif _a < _b: # a,bが別グループに所属:bのいるグループをaのいるグループに移行
    for j in range(1, n + 1):
      if group[j] == _b:
        group[j] = _a
  elif _a > _b: # a,bが別グループに所属:aのいるグループをbのいるグループに移行
    for j in range(1, n + 1):
      if group[j] == _a:
        group[j] = _b

counter = Counter(filter(lambda g: g != 0,group))
print(group.count(counter.most_common()[0][0]))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
if M == 0:
    print(1)
else:
    ans = {}
    for i in range(M):
        A, B = map(int, input().split())
        if i == 0:
            ans[i] = {A, B}
        else:
            flag = 1
            for k, v in ans.items():
                if A in v or B in v:
                    ans[k].add(A)
                    ans[k].add(B)
                    flag = 0
                    break
            if flag:
                ans[i] = {A, B}

ans_ = 0
for v in ans.values():
    if ans_ < len(v):
        ans_ = len(v)
print(ans_)

Submission status: Runtime Error

Solution code:
##この問題はグループの最大人数を求めれば良い

n,m = map(int,input().split())

a = [list(map(int,input().split())) for i in range(m)]

#print(a[0][1])

l = [n+1]*n
# lで何のグループに属しているか判定する
p = [1]*n
# lでどのグループがどのくらいのpowerを持っているか判定する

##最終的にlがn+1でない中で,pが一番大きいのを解答に出す
##ただ,これでは更新頻度がえぐいため工夫がいる.


for j in range(m):
    if(l[a[j][0]] == n+1 & l[a[j][1]] == n+1):
        if(a[j][0] > a[j][1]):
            l[a[j][0]] = a[j][1]
            l[a[j][1]] = a[j][1]
            p[a[j][1]] = 2
        else:
            l[a[j][0]] = a[j][0]
            l[a[j][1]] = a[j][0]
            p[a[j][0]] = 2

    elif(l[a[j][0]] != n+1 & l[a[j][1]] != n+1):
        if(l[a[j][0]] < l[a[j][1]]):

            ###give up

Submission status: Runtime Error

Solution code:
from collections import defaultdict

def dfs(node, parent):
    if node in visited:
        return 0
    visited.add(node)
    count = 1
    for neighbor in adj_list[node]:
        if neighbor != parent:
            count += dfs(neighbor, node)
    return count

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

A, B = [], []

adj_list = defaultdict(set)
visited = set([])

count = 1

for i in range(M):
    a, b = map(int, input().split())
    adj_list[a].add(b)
    adj_list[b].add(a)

count = 0
for node in range(1, N+1):
    count = max(dfs(node, None), count)
print(count)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())

import networkx as nx

g = nx.Graph()
g_list = []
for i in range(M):
    b, c = map(int, input().split())
    
    g_list.append(b)
    g.add_edges_from([(b,c)])
    
result = 1
for n in g_list:
    tmp = len(nx.single_source_shortest_path(g, n).keys())
    
    if result < tmp:
        result = tmp
print(tmp)

Submission status: Runtime Error

Solution code:
import random
import sys

sys.setrecursionlimit(100000)

n, m = map(int, input().split())
# n, m = 200000, 200000
group = {i: 0 for i in range(1, n+1)}
edge = {}
g_mem = {}
g_num = 0
g_con = set()

for i in range(m):
    a, b = map(int, input().split())
    # a, b = random.sample(range(1,n+1), 2)
    if group[a]==0 and group[b] == 0:
        g_num += 1
        group[a] = g_num
        group[b] = g_num
        g_mem[g_num] = 2
    elif group[a] == 0:
        group[a] = group[b]
        g_mem[group[b]] += 1
    elif group[b] == 0:
        group[b] = group[a]
        g_mem[group[a]] += 1
    elif group[a] != group[b]:
        if edge.get(group[a]):
            edge[group[a]].add(group[b])
        else:
            edge[group[a]] = {group[b]}
        if edge.get(group[b]):
            edge[group[b]].add(group[a])
        else:
            edge[group[b]] = {group[a]}

# print(g_mem)
# print(sum(g_mem.values()))
# print(edge)

g_reached = {i: 0 for i in range(1, g_num+1)}

def dps(g_mem, edge, now):
    count = g_mem[now]
    if edge.get(now):
        for e in edge[now]:
            if g_reached[e] == 0:
                g_reached[e] = 1
                count += g_mem[e]
                for ee in edge[e]:
                    if g_reached[ee] == 0:
                        g_reached[ee] = 1
                        count += dps(g_mem, edge, ee)
    return count


ans = []
for now in range(1, g_num+1):
    if g_reached[now] == 0:
        g_reached[now] = 1
        ans.append(dps(g_mem, edge, now))

# print(ans)
print(max(ans))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())

members = [-1] * N

group_count = 0
groups = [0] * N
group_dict = {}
for m in range(M):
    A, B = map(int, input().split())
    A = A - 1
    B = B - 1
    if members[A]==-1 and members[B]==-1:
        members[A] = members[B] = group_count
        groups[group_count] = 2
        group_dict[group_count] = [A, B]
        group_count += 1
    
    elif members[A]!=-1 and members[B]==-1:
        members[B] = members[A]
        groups[members[A]] += 1
        group_dict[members[A]].append(B)
    
    elif members[B]!=-1 and members[A]==-1:
        members[A] = members[B]
        groups[members[B]] += 1
        group_dict[members[B]].append(A)
    
    else:
        if members[A] != members[B]:
            if len(group_dict[A]) > len(group_dict[B]):
                old = members[B]
                groups[members[A]] += groups[members[B]]
                groups[members[B]] = 0
                group_dict[members[A]] = group_dict[members[A]] +  group_dict[members[B]]
                for aaaaaa in group_dict[members[B]]:
                    members[aaaaaa] = members[A]
                group_dict[old] = []
            else:
                old = members[A]
                groups[members[B]] += groups[members[B]]
                groups[members[A]] = 0
                group_dict[members[B]] = group_dict[members[B]] + group_dict[members[A]]
                for bbbbbb in group_dict[members[A]]:
                    members[bbbbbb] = members[B]
                group_dict[old] = []

ans = max(groups)
if ans == 0:
    print(1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
N, M = list(map(int, input().split()))

d = {i: [] for i in range(1, N + 1)}
for _ in range(M):
    a, b = list(map(int, input().split()))
    d[a].append(b)
    d[b].append(a)

visited = [False for _ in range(N + 1)]


def visit(x):
    if visited[x]:
        return 0
    visited[x] = True

    z = 1
    for y in d[x]:
        z += visit(y)
    return z


m = 1
for i in range(1, N + 1):
    r = visit(i)
    if m < r:
        m = r

print(m)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())

E_list = [[]for i in range(N)]

marks = [False for i in range(N)]

def dfs(n):
    global E_list
    global marks
    global N,M

    marks[n] = True

    steps = 1

    for nx in E_list[n]:
        if not marks[nx]:
            marks[nx] = True
            steps += dfs(nx)
    
    return steps



for i in range(M):
    e1,e2 = map(int,input().split())
   
    E_list[e1-1].append(e2-1)
    E_list[e2-1].append(e1-1)

m = 1


for i in range(N):
    E_list[i] = list(set(E_list[i]))
for i in range(N):
    if not marks[i]:
        st = dfs(i)

    m = max(m,st)


print(m)

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.readline

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

G = {}
for i in range(M):
  ai, bi = map(int, readline().split())
  if ai in G:
    if type(G[ai]) is int:
      G[G[ai]].add(bi)
      G[bi] = G[ai]
    else:
      G[ai].add(bi)
      G[bi] = ai
  elif bi in G:
    if type(G[bi]) is int:
      G[G[bi]].add(ai)
      G[ai] = G[bi]
    else:
      G[bi].add(ai)
      G[ai] = bi
  else:
    G[ai] = {ai, bi}
    G[bi] = ai
ans = 1
for i in G:
  if type(G[i]) is not int:
    if len(G[i]) > ans:
      ans = len(G[i])
print(ans)

Submission status: Runtime Error

Solution code:
import collections
N, M = map(int, input().split())
groups = [0] * (N + 1)
group_num_list = [[0]]
group_num = 1
for _ in range(M):
    A, B = map(int, input().split())
    if groups[A] != 0 and groups[B] != 0:
        if groups[A] != groups[B]:
            group_num -= 1
            lower = min(groups[A], groups[B])
            higher = max(groups[A], groups[B])
            for i in group_num_list[higher]:
                groups[i] = lower
            tmp = group_num_list[higher]
            group_num_list[lower].extend(tmp)
            del group_num_list[higher]
    elif groups[A] != 0:
        groups[B] = groups[A]
        group_num_list[groups[A]].append(B)
    elif groups[B] != 0:
        groups[A] = groups[B]
        group_num_list[groups[B]].append(A)
    else:
        groups[A] = group_num
        groups[B] = group_num
        group_num_list.append([A, B])
        group_num += 1
collection = collections.Counter(groups)
# print(collection)
# print(group_num_list)
print(collection.most_common()[0][1] if collection.most_common()[
      0][0] != 0 else collection.most_common()[1][1])

Submission status: Runtime Error

Solution code:
n, m = list(map(int, input().split()))
am = []
bm = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    am.append(a)
    bm.append(b)

groups = []
for ai, bi in zip(am, bm):
    ag = None
    bg = None
    for g, group in enumerate(groups):
        if ai in group:
            ag = g
        if bi in group:
            bg = g
    if ag is None:
        if bg is None:
            groups.append({ai, bi})
        else:
            groups[bg].add(ai)
    else:
        if bg is None:
            groups[ag].add(bi)
        else:
            if ag != bg:
                ming = min([ag, bg])
                maxg = max([ag, bg])
                groups[ming] = groups[ming].union(groups[maxg])
                del groups[maxg]

max_gr_len = 1
max_gr_len = max([len(group) for group in groups])

print(max_gr_len)

Submission status: Runtime Error

Solution code:
import sys

def main():
    stdin = sys.stdin
    n, m = map(int, stdin.readline().split())

    par = [i for i in range(i)]
    size = [1] * n
    rank = [1] * n

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

    def unite(x, y):
        x = find(x)
        y = find(y)

        if x != y:
            # xとyの属している集合が異なる時
            if rank[x] < rank[y]:
                par[x] = y
                size[y] += size[x]
            else:
                par[y] = x
                size[x] += size[y]
                if rank[x] == rank[y]:
                    rank[x] += 1

    for _ in range(m):
        a, b = map(int, stdin.readline().split())
        unite(a, b)


    print(max(size))

if __name__ == '__main__':

Submission status: Runtime Error

Solution code:
import queue
n, m = map(int,input().split())
A=[]
B=[]
conne = [[0]*n for _ in range(n)]
visited = [0]*n

for i in range(m):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    conne[a-1][b-1]=1
    conne[b-1][a-1]=1

ans=0
for i in range(n):
    
    d=1
    count=0
    if visited[i]==0:
        visited[i]=1
        q=queue.Queue()
        q.put((i,d))
        count+=1
        
        while not q.empty():
            x,d = q.get()
            
            for j in range(n):
                if visited[j]==0 and conne[x][j]==1:
#                    print(i,j)
                    visited[j]=1
                    count+=1
                    q.put((j,d+1))
                    
                    
    ans = max(count,ans)
    
print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())

import networkx as nx

g = nx.Graph()
g_list = []
for i in range(M):
    b, c = map(int, input().split())
    
    g_list.append(b)
    
    g.add_edges_from([(b,c)])
    
result = 1
for n in g_list:
    
    if n not in g_list:
        continue
    node_n = n+1
    tmp = len(nx.single_source_shortest_path(g, node_n).keys())
    
    if result < tmp:
        result = tmp
print(tmp)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = [0] * N
for i in range(N - 1):
    find(i)
print(0)

Submission status: Runtime Error

Solution code:
import collections
n,m = map(int, input().split())

friends = [0] * n
query = []

for i in range(m):
  a,b = map(int, input().split())
  if friends[a - 1] == 0 and  friends[b - 1] == 0:
    friends[a - 1] = tmp
    friends[b - 1] = tmp
    tmp += 1
  elif friends[a - 1] == 0:
    friends[a - 1] = friends[b - 1]
  elif friends[b - 1] == 0:
    friends[b - 1] = friends[a - 1]
  else:
    index_num = [n for n, v in enumerate(friends) if v == friends[a - 1]]
    duplicated = friends[b - 1]
    for i in index_num:
      friends[i] = duplicated

counted = collections.Counter(friends)
if counted.most_common()[0][1] != 0:
  print(counted.most_common()[0][1])
else:
  print(counted.most_common()[0][2])

Submission status: Runtime Error

Solution code:
import sys

def main():
    stdin = sys.stdin
    n, m = map(int, stdin.readline().split())

    par = [i for i in range(i)]
    size = [1] * n
    rank = [1] * n

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

    def unite(x, y):
        x = find(x)
        y = find(y)

        if x != y:
            # xとyの属している集合が異なる時
            if rank[x] < rank[y]:
                par[x] = y
                size[y] += size[x]
            else:
                par[y] = x
                size[x] += size[y]
                if rank[x] == rank[y]:
                    rank[x] += 1

    for _ in range(m):
        a, b = map(int, stdin.readline().split())
        unite(a, b, par, rank)


    print(max(size))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
info = []
count = 0
people = set()
friends = []
while count < M:
    A, B = map(int,input().split())
    info += [[A,B]]
    people.union({A,B})
    if A in people and B not in people:
        for f in friends:
            if A in f:
                f += [B]
    elif B in people and A not in people:
        for f in friends:
            if B in f:
                f += [A]
    elif A not in people and B not in people:
        friends += [[A,B]]
    count += 1

print(max(len(f) for f in friends))