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: Wrong Answer

Solution code:
N, M = map(int, input().split())
l = [-1]*N
f = []
cnt = 0
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if l[a] < 0 and l[b] < 0:
        f.append([a, b])
        l[a] = cnt
        l[b] = cnt
        cnt += 1
    elif l[a] >= 0 and l[b] < 0:
        f[l[a]].append(b)
        l[b] = l[a]
    elif l[b] >= 0 and l[a] < 0:
        f[l[b]].append(a)
        l[a] = l[b]
    elif l[b] != l[a]:
        if len(f[l[a]]) > len(f[l[b]]):
            for i in f[l[b]]:
                l[i] = l[a]
                f[l[a]].append(i)
        else:
            for i in f[l[a]]:
                l[i] = l[b]
                f[l[b]].append(i)
ans = 0
for l in f:
    ans = max(ans, len(l))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.rank = [0 for i in range(n)]

    def getParents(self):
        return self.parent

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

    def unite(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if (root_x == root_y):
            return
        elif self.rank[root_x] > self.rank[root_y]:
            self.parent[root_y] = root_x

        elif self.rank[root_y] > self.rank[root_x]:
            self.parent[root_x] = root_y

        else:
            self.parent[root_x] = root_y
            self.rank[root_y] += 1

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def memsInGroup(self, x):
        """
        O(N)かかります
        """
        root = self.find(x)
        return [i for i in range(N) if root == self.find(i)]

    def sizeOfGroup(self, x):
        return len(self.memsInGroup(x))


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

friend = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    friend.unite(a-1, b-1)

roots = friend.getParents()
counts = Counter(roots)

ans = max(counts.values())
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
num=[[_+1] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    num[a-1].append(b)
    num[b-1].append(a)
ans=0
for i in range(n):
    cnt=set()
    for j in range(len(num[i])):
        num3=num[num[i][j]-1]
        for k in range(len(num3)):
            cnt.add(num3[k])
    ans=max(ans,len(cnt))
print(ans)

Submission status: Wrong Answer

Solution code:
# https://note.nkmk.me/python-union-find/
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 = 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
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N, M = map(int,input().split())
G = defaultdict(set)
for _ in range(M):
  a,b = map(int,input().split())
  G[a].add(b)
  G[b].add(a)

ans = 0
for i in G.values():
  ans = max(len(i),ans)
print(ans+1)

Submission status: Wrong Answer

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################
n , m = map(int , input().split())
dic = defaultdict(set)
for ii in range(m):
	u,v = map(int , input().split())
	dic[u].add(v)
	dic[v].add(u)
ans = 0
for k,v in dic.items():
	ans = max(len(v),ans)
print(ans+1)

Submission status: Wrong Answer

Solution code:
import collections

n,m=map(int,input().split())
grouplist=[i for i in range(n)]
for i in range(m):
    f=list(map(int,input().split()))
    f[0]-=1
    f[1]-=1
    grouplist[max(f)]=grouplist[min(f)]

c=collections.Counter(grouplist)
print(c.most_common()[0][1])

Submission status: Wrong Answer

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

fMap = {}
count = 0
lister = []

for i in range(m):
    a, b = map(int, input().split())
    if a in fMap:
        if not b in fMap:
            lister[fMap[a]].append(b)
        fMap[b] = fMap[a]
    elif b in fMap:
        if not a in fMap:
            lister[fMap[b]].append(a)
        fMap[a] = fMap[b]
    else:
        fMap[a] = count
        fMap[b] = count
        count+=1
        lister.append([a, b])
maxL = 0
for l in lister:
    if len(l) > maxL:
        maxL = len(l)
print(maxL)

Submission status: Wrong Answer

Solution code:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n,m = readInt()
    a = [set() for i in range(n)]
    b = [set() for i in range(n)]
    for i in range(m):
        x,y = readInt()
        a[y-1].add(x-1)
        a[x-1].add(y-1)
    ans = [0 for i in range(n)]
    for i in range(n):
        ans[i] = len(a[i])
    print(max(ans)+1)
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if b not in graph[a]:
        graph[a].append(b)
        graph[b].append(a)
color_list = [-1 for _ in range(n)]
from collections import deque
color = -1
for i in range(n):
    if color_list[i] > -1:
        continue
    else:
        q = deque([i])
        color += 1
        while q:
            tmp = q.popleft()
            for g in graph[tmp]:
                if color_list[g] == -1:
                    color_list[g] = color
                    q.append(g)
ans = 0
for i in range(color + 1):
    ans = max(ans, color_list.count(i))
print(ans)

Submission status: Wrong Answer

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

    par = [x for x in range(n)]
    rank = [0]*n

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

    def unite(x, y):
        x = find(x)
        y = find(y)
        if x == y: return
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]: rank[x] += 1

    for _ in range(m):
        a, b = map(lambda x: int(x)-1, input().split())
        unite(a, b)

    from collections import Counter
    ans = Counter(par).most_common()[0][1]
    print(ans)

if __name__ == '__main__':
    abc177_d()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
union = []
sets = []
for i in range(n+1):
    union.append(i)
    sets.append({i})

def root(n):
    global union
    if union[n] == n:
        return n
    res = union[union[n]]
    union[n] = res
    return res

def isSameRoots(n, m):
    nRoot = root(n)
    mRoot = root(m)
    return nRoot == mRoot

def unit(n, m):
    global union
    global sizeU
    global sets
    nRoot = root(n)
    mRoot = root(m)
    sets[nRoot] = sets[nRoot] | sets[mRoot]
    union[mRoot] = root(nRoot)

for i in range(m):
    inA, inB = map(int, input().split())
    if not isSameRoots(inA, inB):
        unit(inA, inB)
ans = 0
for i in range(1, n+1):
  ans = max(len(sets[root(i)]), ans)
print(ans)

Submission status: Wrong Answer

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

group = [0]*n
group_num = 1

for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    a1 = group[a]  
    b1 = group[b]
    if a1 == 0 and b1 == 0:
        group[a] = group_num
        group[b] = group_num
        group_num += 1
    elif a1 != 0:
        group[b] = a1
    else:
        group[a] = b1

group.sort()
group_num1 = 1
cnt = 1

for i in range(1,n):
    if group[i] == group[i-1]:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 1
ans = max(ans,cnt)

if m != 0:
    print(ans)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
x=[[i,1] for i in range(n+1)]
x[0][1]=0
for i in range(m):
    a,b=map(int,input().split())
    p=[]
    if x[a][0]!=x[b][0]:
        p.append(x[a][1])
        p.append(x[b][1])
        x[a][1]+=p[1]
        x[b][1]+=p[0]
        x[a][0]=min(a,b)
        x[b][0]=min(a,b)
ans=0
for i in range(n):
    ans=max(ans,x[i+1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
class union_find:
    def __init__(self, N):
        # 子なら親のインデックス、親ならunionのサイズを負数で格納
        self.par = [-1 for i in range(N)]
    
    def root(self, i):
        if self.par[i] < 0:
            return i
        else:
            # 経路圧縮
            self.par[i] = self.root(self.par[i])
            return self.par[i]
    
    def same(self, a, b):
        return self.root(a) == self.root(b)
    
    def unite(self, a, b):
        if not self.same(a, b):
            self.par[a] = self.root(b)
            self.par[self.root(a)] -= 1

N, M = list(map(int, input().split()))
UF = union_find(N)
for _ in range(M):
    A, B = list(map(lambda x: int(x) - 1, input().split()))
    UF.unite(A, B)
print(-min(UF.par))

Submission status: Wrong Answer

Solution code:
import os
import heapq
import sys,threading
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

sys.setrecursionlimit(10 ** 5)
threading.stack_size(2**27)


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""


def inpt():
    return [int(k) for k in input().split()]

global ct

def dfs(d,visited,s):
    global ct
    ct+=1
    visited[s]=True

    for i in d[s]:
        if(not visited[i]):
            dfs(d,visited,i)

def main():
    n,m=inpt()
    st=set()
    d=defaultdict(list)
    for _ in range(m):
        a,b=inpt()
        if((min(a,b),max(a,b)) not in st):
            st.add((min(a,b),max(a,b)))
            d[a].append(b)
            d[b].append(a)

    visited=[False]*(n+1)
    ans=0
    for i in range(1,n+1):
        global ct
        ct=0
        if(not visited[i]):
            dfs(d,visited,i)
            ans=max(ans,ct)
    print(ans)







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")

if __name__ == "__main__":
    #main()
    threading.Thread(target=main).start()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
d={k:[] for k in range(1,n+1)}
for a,b in l:
    d[a].append(b)
    d[b].append(a)
ans=0
for s in d.values():
    ans=max(ans,len(set(s))+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


class UnionFind:
    def __init__(self, N):
        self.tree = list(range(N))

    def root(self, N):
        if self.tree[N] == N:
            return N
        else:
            self.tree[N] = self.root(self.tree[N])
            return self.tree[N]

    def same(self, x, y):
        return self.root(self.tree[x]) == self.root(self.tree[y])

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        else:
            self.tree[x] = y


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    uf = UnionFind(N)
    for _ in range(M):
        a, b = il()
        tmp = sorted((a - 1, b - 1))
        uf.unite(tmp[1], tmp[0])
    print(max(collections.Counter(uf.tree).values()))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
l = [i for i in range(n+1)]
for i in range(m):
    if l[ab[i][0]] > l[ab[i][1]]:
        l[ab[i][0]] = l[ab[i][1]]
    else:
        l[ab[i][1]] = l[ab[i][0]]

ans_l = [0 for i in range(n+1)]
for i in range(n+1):
    ans_l[l[i]] += 1

print(max(ans_l))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
ans = [set()]
for i in range(M):
    A_i, B_i = map(int, input().split())
    for i in range(len(ans)):
        if A_i in ans[i] or B_i in ans[i]:
            ans[i].add(A_i)
            ans[i].add(B_i)
            break
        if i == len(ans) - 1:
            ans.append({A_i, B_i})
maximum = 0
for i in range(len(ans)):
    maximum = max(maximum, len(ans[i]))
print(maximum)

Submission status: Wrong Answer

Solution code:
def LI():
    return list(map(int, input().split()))


N, M = LI()
friend = [[] for _ in range(N)]
ans = 0
for i in range(M):
    a, b = map(int, input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
for i in friend:
    ans = max(ans, len(set(i)))
print(ans+1)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
Groups = [{i} for i in range(N)]
dsts = [-1 for i in range(N)]
for i in range(M):
    A, B = [int(i)-1 for i in input().split()]
    dst = min(A, B)
    src = max(A, B)
    while(dsts[dst] != -1):
        dst = dsts[dst]
    dsts[src] = dst
    Groups[dst] = Groups[dst] | Groups[src]

ans = 0
for group in Groups:
    ans = max(ans, len(group))
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
group = [set([i]) for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    group[a-1].add(b-1)
    group[b-1].add(a-1)
for i, g in enumerate(group):
    group[i] = g.union(*[group[x] for x in g])
r = 0
for g in group:
    r = max(len(g), r)
print(r)

Submission status: Wrong Answer

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

fMap = {}
count = 0
lister = []

for i in range(m):
    a, b = map(int, input().split())
    if a in fMap:
        if not b in fMap:
            lister[fMap[a]].append(b)
        fMap[b] = fMap[a]
    elif b in fMap:
        if not a in fMap:
            lister[fMap[b]].append(a)
        fMap[a] = fMap[b]
    else:
        fMap[a] = count
        fMap[b] = count
        lister.append([a, b])
maxL = 0
for l in lister:
    if len(l) > maxL:
        maxL = len(l)
print(maxL)

Submission status: Wrong Answer

Solution code:
import collections
n,m=map(int,input().split(" "))
L=[i+1 for i in range(n)]

  
for i in range(m):
  x,y=map(int,input().split(" "))
  if x<=y:
    L[y-1]=L[x-1]
  else:
    L[x-1]=L[y-1]
c = collections.Counter(L)
print(c.most_common()[0][1])

Submission status: Wrong Answer

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

group = [0]*n
group_num = 1

for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    a1 = group[a]  
    b1 = group[b]
    if a1 == 0 and b1 == 0:
        group[a] = group_num
        group[b] = group_num
        group_num += 1
    elif a1 != 0:
        group[b] = a1
    else:
        group[a] = b1

group.sort()
group_num1 = 1
cnt = 1

for i in range(1,n):
    if group[i] == group[i-1]:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 1
ans = max(ans,cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

friends = [0 for _ in range(N)]
#print(friends)

for _ in range(M):
  A, B = map(int, input().split())
  if friends[A - 1] != 0:
    friends[B - 1] = friends[A - 1]
  elif friends[B - 1] != 0:
    friends[A - 1] = friends[B - 1]
  else:
    friends[A - 1] = A
    friends[B - 1] = A


for i in range(N):
  if friends[i] == 0:
    friends[i] = i + 1
    
  #print(friends)
  
print(max(Counter(friends).values()))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
groups = [set(map(int, input().split())) for _ in range(M)]

no = set()
ans = 2
for i in range(1, len(groups)):
    for j in range(i):
        if j in no:
            continue
        if len(groups[i]&groups[j]) > 0:
            groups[i] = groups[i] | groups[j]
            ans = max(ans, len(groups[i]))
            no.add(j)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections


class unionFind:
    parent = []

    def __init__(self, N):
        self.parent = [i for i in range(N)]

    def root(self, x):
        if self.parent[x] == x:
            return(x)
        else:
            self.parent[x] = self.root(self.parent[x])
            return(self.parent[x])

    def same(self, x, y):
        x, y = x-1, y-1
        return(self.root(x) == self.root(y))

    def unite(self, x, y):
        x, y = x-1, y-1
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        else:
            self.parent[x] = y
            return


N, M = map(int, input().split())
G = unionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    G.unite(a, b)
print(1)

# for i in range(N):
#     G.root(i)

# C = collections.Counter(G.parent).most_common()

# print(C[0][1])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N, M = MI()
    relations = [set([]) for i in range(N)]
    for i in range(M):
        a, b = MI()
        a -= 1
        b -= 1
        relations[a].add(b)
        relations[b].add(a)

    grouped = [-1] * N
    group_num = [0] * N

    group = 0

    for i in range(len(grouped)):
        if grouped[i] != -1:
            continue
        deque = cl.deque(relations[i])
        group += 1

        while len(deque) > 0:
            target = deque.popleft()
            friends = relations[target]
            for friend in friends:
                if grouped[friend] != -1:
                    continue
                grouped[friend] = group
                group_num[group] += 1
                deque.append(friend)

    print(max(group_num))


main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
connect = []
for i in range(m):
    connect.append(sorted(list(map(int, input().split()))))
con = {}
for i in range(m):
    try:
        con[connect[i][0]].append(connect[i][1])
        con[connect[i][0]] = list(set(con[connect[i][0]]))
    except KeyError:
        con[connect[i][0]] = [connect[i][1]]
a = 0
for i in con:
    a = max(a, len(con[i])+1)
print(a)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.size[x] < self.size[y]:
                x,y = y,x
            self.parents[y] = x
            self.size[x] += self.size[y]

def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for i in range(M):
        a, b = map(lambda x: int(x)-1, input().split())
        uf.union(a,b)

    l = Counter(uf.parents)
    print(max(l.values()))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections

n,m=map(int,input().split())
grouplist=[i for i in range(n)]
flist=[]
for i in range(m):
    f=list(map(int,input().split()))
    f[0]-=1
    f[1]-=1
    flist.append(f)
flist.sort()

for i in range(m):
    f=flist[i]
    grouplist[max(f)]=grouplist[min(f)]

c=collections.Counter(grouplist)
print(c.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
fs = [list(map(int, input().split())) for i in range(m)]

g = [set([i]) for i in range(n + 1)]
for a, b in fs:
    g[a].add(b)
    g[b].add(a)

ans = 0
for i in g:
    ans = max(ans, len(i))
print(ans)