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,t = list(map(int,input().split()))
graph = [[] for _ in range(n)]
visited = [0]*n
for _ in range(t):
    a,b = list(map(int,input().split()))
    a -= 1;b -= 1
    graph[a].append(b)
    graph[b].append(a)
def dfs(now):
    visited[now] = 1
    num = 1
    for i in graph[now]:
        if not visited[i]:
            num += dfs(i)
    return num
ans = 0
for i in range(n):
    if not visited[i]:
        ans = max(ans,dfs(i))

print(ans)

# allsets = []
# n,t = list(map(int,input().split()))
# for _ in range(t):
#     a,b = list(map(int,input().split()))
#     if a < b and [a,b] not in allsets:
#         allsets.append([a,b])
#     elif b < a and [b,a] not in allsets:
#         allsets.append([b,a])
# # print(allsets)
# hmap = {}
# visitedNode = {}
# for a,b in allsets:
#     if a in visitedNode:
#         if b not in hmap[visitedNode[a]]:
#             hmap[visitedNode[a]].append(b)
#         del visitedNode[a]
#         continue
#     if a in hmap:
#         hmap[a].append(b)
#         visitedNode[b] = a
#     else:
#         hmap[a] = [b]
#         visitedNode[b] = a
# # print(hmap)
# res = 0
# for k,v in hmap.items():
#     res = max(res,len(v)+1)
# print(res)

Submission status: Runtime Error

Solution code:
from collections import Counter

class UnionFindBasic():
    """via https://note.nkmk.me/python-union-find/#_3
    """
    def __init__(self, n):
        self.parents = list(range(n))

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y: return
        self.parents[y] = x

if __name__ == '__main__':
    N, M = map(int, input().split())

    uf = UnionFindBasic(N)

    for _ in range(M):
        a,b = list(map(lambda x: int(x)-1, input().split()))
        if a < b:
            uf.union(a,b)
        else:
            uf.union(b,a)

    print(Counter(uf.parents).most_common()[0][1])

Submission status: Runtime Error

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key
from bisect import bisect_left


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

def bindex(a,x):
    i = bisect_left(a,x)
    if i != len(a) and a[i] == x:
        return i
    return None

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)


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

    def root(self, x):
        if self.r[x] < 0:
            return x
        self.r[x] = self.root(self.r[x])
        return self.r[x]
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.r[x] > self.r[y]:
            tmp = x
            x = y
            y = x
        self.r[x] += self.r[y]
        self.r[y] = x
        return True

    def size(self, x):
        return -1 * self.r[self.root(x)]



if __name__ == '__main__':
    # N, M = mulinputs()
    # b = [None] * (N+1)
    # for _ in range(M):
    #     A, B = map(int,input().split())
    #     if not b[A] and b[B]:
    #         b[B].add(A)
    #         b[A] = b[B]
    #     elif b[A] and not b[B]:
    #         b[A].add(B)
    #         b[B] = b[A]
    #     elif not b[A] and not b[B]:
    #         t = set([A,B])
    #         b[A] = t
    #         b[B] = t
    #     else:
    #         b[A].add(B)
    #         b[B].add(A)
    # # 出力
    # ans = 1
    # for bb in b:
    #     if not bb:
    #         continue
    #     ans = max(ans, len(bb))
    # print(ans)

    N, M = mulinputs()
    uf = UnionFind(N)
    for _ in range(M):
        A, B = map(int,input().split())
        uf.unite(A-1, B-1)
    ans = 1
    for i in range(M):
        ans = max(ans, uf.size(i))
    print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
t = [-1*(i+1) for i in range(n)]
count = 0
for _ in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    if t[a] <= -1 and t[b] <= -1:
        count += 1
        t[a] = count
        t[b] = count
        continue
    if t[a] > -1 and t[b] > -1 and t[a] != t[b]:
        max_t = max(t[a], t[b])
        min_t = min(t[a], t[b])
        t[a] = max_t
        t[b] = max_t
        t = map(lambda x: max_t if x == min_t else x, t)
        continue
    if t[a] > -1 and t[b] > -1 and t[a] == t[b]:
        continue
    if t[a] <= -1:
        t[a] = t[b]
        continue
    if t[b] <= -1:
        t[b] = t[a]

print(
    max([t.count(i) for i in set(t)])
)

Submission status: Runtime Error

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

tree = [[] for i in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for i in range(n+1):
    tree[i] = list(set(tree[i]))

visited = [False for i in range(n+1)]


def add(x, count):
    for i in range(len(tree[x])):
        if visited[tree[x][i]] == False:
            count += 1
            visited[tree[x][i]] = True
            count = add(tree[x][i], count)
    return count

max_count = -1
for i in range(1, n+1):
    if visited[i] == False:
        visited[i] = True
        count = 1
        count = add(i, count)
        max_count = max(count, max_count)
print(max_count)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
branch = set(tuple(map(int,input().split())) for i in range(m))
que = range(n)
flag = -1
friend = [{1}]

for a,b in branch:
    for i in range(len(friend)):
        if (a in friend[i]) or (b in friend[i]):
            friend[i].add(a)
            friend[i].add(b)
            if flag >= 0:
                friend[flag] = friend[flag]|friend[i]
                friend.pop(i)
            flag = i
    if flag == -1:
        friend.append({a,b})
    else: flag = -1

len_friend = list(len(i) for i in friend)
print(max(len_friend))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
g = [[False, []] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a][1].append(b)
    g[b][1].append(a)


def dfs(i):
    if g[i][0]:
        return 0
    v = 1
    g[i][0] = True
    for j in g[i][1]:
        v += dfs(j)
    return v


ans = 0
for i in range(n):
    ans = max(ans, dfs(i))
print(ans)

Submission status: Runtime Error

Solution code:
"""
自分の解答
"""

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

R = [set(map(int, input().split(" "))) for i in range(M)]

groups = []
while len(R) > 0:
    r = R.pop()
    for r_ in R:
        if len(r & r_) > 0:
            r |= r_
    groups.append(r)

print(max(map(len, groups)))

Submission status: Runtime Error

Solution code:
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])):
        chk[d[temp][i]-1]=1
        d[temp].append(d[temp][i])
        q.append(d[temp][i])

    if len(q)>0:
        while a<N:
            if chk[a]==0:
                chk[a]=1
                temp=a+1
                break
            a+=1
    else:
        temp=q.pop()

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

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
branch = list(tuple(map(int,input().split())) for i in range(m))
que = range(n)
flag = -1
friend = [{1}]

for a,b in branch:
    for i in range(len(friend)):
        if (a in friend[i]) or (b in friend[i]):
            friend[i].add(a)
            friend[i].add(b)
            if flag >= 0:
                friend[flag] = friend[flag]|friend[i]
                friend.pop(i)
            flag = i
    if flag == -1:
        friend.append({a,b})
    else: flag = -1

len_friend = list(len(i) for i in friend)
print(max(len_friend))

Submission status: Runtime Error

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

R = [set(map(int, input().split(" "))) for i in range(M)]

groups = []
while len(R) > 1:
    r = R.pop()
    for r_ in R:
        if len(r & r_) > 0:
            r |= r_
    groups.append(r)

print(max(map(len, groups)))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
branch = list(tuple(map(int,input().split())) for i in range(m))
que = range(n)
flag = -1
friend = [{1}]

for a,b in branch:
    for i in range(len(friend)):
        if (a in friend[i]) or (b in friend[i]):
            friend[i].add(a)
            friend[i].add(b)
            if flag >= 0:
                friend[flag] = friend[flag]|friend[i]
                friend.pop(i)
            flag = i
    if flag == -1:
        friend.append({a,b})
    else: flag = -1

print(friend)
len_friend = list(len(i) for i in friend)
print(max(len_friend))

Submission status: Runtime Error

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

R = [set(map(int, input().split(" "))) for i in range(M)]

groups = []
while len(R) > 1:
    r = R.pop()
    for r_ in R:
        if len(r & r_) > 0:
            r |= r_
    groups.append(r)

print(max(map(len, groups)))

Submission status: Runtime Error

Solution code:
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])):
        chk[d[temp][i]-1]=1
        q.append(d[temp][i])

    if len(q)>0:
        while a<N:
            if chk[a]==0:
                chk[a]=1
                temp=a+1
                break
            a+=1
    else:
        temp=q.pop()

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

Submission status: Runtime Error

Solution code:
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])):
        chk[d[temp][i]-1]=1
        q.append(d[temp][i])

    if len(q)>0:
        while a<N:
            if chk[a]==0:
                q.append(a+1)
            a+=1
    else:
        temp=q.pop()

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

Submission status: Runtime Error

Solution code:
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-08-29 22:53
# @url:https://atcoder.jp/contests/abc177/tasks/abc177_d
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    n,m=map(int,input().split())
    pairs=[]
    for i in range(m):
        a,b=map(int,input().split())
        temp=[]
        temp.append(a)
        temp.append(b)
        pairs.append(temp)
    fa=[i for i in range(2*10**6+1)]
    def find(x):
        if x!=fa[x]:
            fa[x]=find(fa[x])
        return fa[x]
    def union(x,y):
        x = find(x)
        y = find(y)
        if x == y:  
            return
        fa[x] = y
    for (i,j) in pairs:
        union(i,j)
    for (i,j) in pairs:
        union(j,i)
    d=collections.Counter(fa)
    # print (fa)
    sd=sorted(d.items(),key=lambda x:x[1])
    # print (sd)
    if len(sd)>0:
        print (sd[-1][1])
    else:
        print (0)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from UnionFind import UnionFind as UF

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

uf = UF(N)

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

z=0
c=[0]*N
for i in range(N):
    p=uf.root(i)
    c[p]+=1
    if z<c[p]:
        z=c[p]

print(z)

Submission status: Runtime Error

Solution code:
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])):
        chk[d[temp][i]-1]=1
        q.append(d[temp][i])

    if len(q)>0:
        while a<N:
            if chk[a]==0:
                q.append(a+1)
            a+=1
    else:
        temp=q.pop()

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict as dd
from collections import deque
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])):
        chk[d[temp][i]-1]=1
        q.append(d[temp][i])

    if len(q)>0:
        while a<N:
            if chk[a]==0:
                q.append(a+1)
            a+=1
    else:
        temp=q.pop()

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

Submission status: Runtime Error

Solution code:
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-08-29 22:53
# @url:https://atcoder.jp/contests/abc177/tasks/abc177_d
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    n,m=map(int,input().split())
    pairs=[]
    for i in range(m):
        a,b=map(int,input().split())
        temp=[]
        temp.append(a)
        temp.append(b)
        pairs.append(temp)
    fa=[i for i in range(2*10**5+1)]
    def find(x):
        if x!=fa[x]:
            fa[x]=find(fa[x])
        return fa[x]
    def union(x,y):
        x = find(x)
        y = find(y)
        if x == y:  
            return
        fa[x] = y
    for (i,j) in pairs:
        union(i,j)
    for (i,j) in pairs:
        union(j,i)
    d=collections.Counter(fa)
    # print (fa)
    sd=sorted(d.items(),key=lambda x:x[1])
    # print (sd)
    if len(sd)>0:
        print (sd[-1][1])
    else:
        print (0)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
if M == 0:
  print(1)
else:
  F = list((sorted(map(int,input().split()))) for i in range(M))
  L = list(map(list,set(map(tuple,F))))
  
  team = []
  for i in range(len(L)):
    if i == 0:
      team.append(L[i])
    else:
      for j in range(len(team)):
        if L[i][0] in team[j] and L[i][1] not in team[j]:
          team[j].append(L[i][1])
          break
        elif L[i][0] not in team[j] and L[i][1] in team[j]:
          team[j].append(L[i][0])
          break
      else:
        team.append(L[i])
team_l = [len(k) for k in team]
print(max(team_l))

Submission status: Runtime Error

Solution code:

class UnionFind:
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]

    def find(self, s):
        if self.parent[s] < 0:
            return s
        self.parent[s] = self.find(self.parent[s])
        return self.parent[s]

    def union(self, a, b):
        a, b = self.find(a), self.find(b)
        if a == b:
            return
        self.parent[a] += self.parent[b]
        self.parent[b] = a

    def size(self, x):
        return -1 * self.parent[self.find(x)]

n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    a, b = list(map(int, input().split()))
    uf.union(a - 1, b - 1)
print(max([uf.size(i) for i in range(n)]))

Submission status: Runtime Error

Solution code:
def main():
    n, m, *ab, = map(int, open(0).read().split())

    p = [-1] * (n + 1)

    def f(x):
        if p[x] < 0:
            return x
        else:
            return f(p[x])

    ans = -1
    for i, j in zip(ab[::2], ab[1::2]):
        if i > j:
            i, j = j, i

        pi, pj = f(i), f(j)
        if pi == pj:
            continue
        p[pi] += p[pj]
        ans = min(ans, p[pi])
        p[j] = pi
        p[pj] = pi

    print(-ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def search(x, num):
    nodes.remove(x)
#     for y in edge[x]:
#         edge[y].discard(x)
#     for y in list(edge[x]):
    for y in edge[x]:
        if y in nodes:
            num = search(y, num)
    return num + 1

(n,m),*d  = [list(map(int, s.split())) for s in open(0)]

edge = [set() for _ in range(n+1)]
for x in d:
    edge[x[0]].add(x[1])
    edge[x[1]].add(x[0])

nodes = set(range(1,n+1))
ans = 1
for x in list(nodes):
    if x in nodes:
        ans = max(ans, search(x, 0))
print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
if M == 0:
  print(1)
else:
  F = list((sorted(map(int,input().split()))) for i in range(M))
  L = sorted(list(map(list,set(map(tuple,F)))))
  
  team = []
  for i in range(len(L)):
    if i == 0:
      team.append(L[i])
    else:
      for j in range(len(team)):
        if L[i][0] in team[j] and L[i][1] not in team[j]:
          team[j].append(L[i][1])
          break
        elif L[i][0] not in team[j] and L[i][1] in team[j]:
          team[j].append(L[i][0])
          break
      else:
        team.append(L[i])
team_l = [len(k) for k in team]
print(max(team_l))

Submission status: Runtime Error

Solution code:
def search(x, num):
    nodes.remove(x)
#     for y in edge[x]:
#         edge[y].discard(x)
    for y in list(edge[x]):
        if y in nodes:
            num = search(y, num)
    return num + 1

(n,m),*d  = [list(map(int, s.split())) for s in open(0)]

edge = [set() for _ in range(n+1)]
for x in d:
    edge[x[0]].add(x[1])
    edge[x[1]].add(x[0])

nodes = set(range(1,n+1))
ans = 1
for x in list(nodes):
    if x in nodes:
        ans = max(ans, search(x, 0))
print(ans)

Submission status: Runtime Error

Solution code:
def search(x, num):
    nodes.remove(x)
    for y in edge[x]:
        edge[y].discard(x)
    for y in list(edge[x]):
        if y in nodes:
            num = search(y, num)
    return num + 1

(n,m),*d  = [list(map(int, s.split())) for s in open(0)]

edge = [set() for _ in range(n+1)]
for x in d:
    edge[x[0]].add(x[1])
    edge[x[1]].add(x[0])

nodes = set(range(1,n+1))
ans = 1
for x in list(nodes):
    if x in nodes:
        ans = max(ans, search(x, 0))
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
#input = lambda: sys.stdin.readline().strip()
#◆◆◆◆◆◆提出前には上の#を削除する◆◆◆◆◆◆
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
 
    N, M = NMI()
    AB = [NLI() for _ in range(M)]
    
    #各頂点の遡った親が同じなら、同じグループ
    parents = [i for i in range(N+1)] # 最初は自分自身が親。
 
    
    def find_parent(x):#ある子の親を探す
        if parents[x] == x:#自分自身が親ならそれでいい
            return parents[x]
        else:
            parents[x] = find_parent(parents[x])#親の値を親の親の…親に書き換える
            return parents[x]
    
    
    def unite_children(x,y):#親を同じにする
        parent_x = find_parent(x)
        parent_y = find_parent(y)
        if parent_x == parent_y:#すでに親が同じなら何もしない
            return
        parents[x] = y

 
        
    for m in range(M):
        a = AB[m][0]
        b = AB[m][1]
        
        if a > b:
            a,b = b,a
        
        unite_children(a,b)

    
    for m in range(1,M+1):
        parents[m] = find_parent(m)

    del parents[0]
    pa = collections.Counter(parents)
    
    print(pa.most_common()[0][1])
 

 
 
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
val=1
dic={}
friends={1:[]}
for i in range(n+1):
    dic[i]=0
a,b=map(int,input().split())
friends[1].append(a)
friends[1].append(b)
for i in range(m-1):
    a,b=map(int,input().split())
    flag=0
    for j in list(friends.keys()):
        if a in friends[j] and (b not in friends[j]):
            friends[j].append(b)
            flag=1
            break
        elif b in friends[j] and (a not in friends[j]):
            friends[j].append(a)
            flag=1
            break
    if flag==0:
        val+=1
        friends[val]=[a,b]
maxx=0
for j in friends:
    maxx=max(maxx,len(friends[j]))
print(maxx)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
UF = [-1] * (N+1)
def find(x):
    global UF
    if UF[x] == -1:
        return x
    else:
        UF[x] = find(UF[x])
        return UF[x]
def union(x,y):
    global UF
    xx = find(x)
    yy = find(y)
    if UF[x] == UF[y] == -1:
        UF[y] = xx
        return
    elif xx == yy:
        return 
    else:
        UF[yy] = xx
        return 
    
for _ in range(M):
    x, y = map(int, input().split())
    union(x,y)
    
cnt = [0] * (N+1)
for i in range(1,N+1):
    z = find(i)
    cnt[z] += 1

print(max(cnt))