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())
friends = []
for _ in range(m):
    friends.append(tuple(map(int, input().split())))

groups = []
for friend in friends:
    if len(groups) == 0:
        groups.append(set(friend))
    else:
        for i, group in enumerate(groups):
            if friend[0] in group or friend[1] in group:
                groups[i] = set.union(group, set(friend))
                break
            else:
                groups.append(set(friend))

max_len = 0
for group in groups:
    max_len = max(max_len, len(group))
print(max_len)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

ans = 0
graph = [[] for _ in range(N+1)]

for i in range(M):
    A, B = map(int, input().split())
    graph[A].append(B)
    graph[B].append(A)

for i in range(N):
    num = len(set(graph[i])) + 1
    if ans < num:
        ans = num

print(ans)

Submission status: Wrong Answer

Solution code:
x =lambda:list(map(int,input().split()))

n,m=x()
adjac = {i:[] for i in range(1,n+1)}

for _ in range(m):
    a,b = x()
    adjac[a].append(b)
    adjac[b].append(a)

comp = []

visited = {i:False for i in range(1,n+1)}

for i in range(1,n+1):
    if not visited[i]:
        queue = [i]
        count=1
        while len(queue)!=0:
            h=queue[-1]
            queue.pop(0)
            arr = adjac[h]
            for j in arr:
                if not visited[j]:
                    visited[j]=True
                    queue.append(j)
                    count+=1
        if count!=1:
            comp.append(count-1)

# print(comp)
comp.sort()
ans=0
sub = 0
for i in range(0,len(comp)):
    # print(sub)
    app = comp[i]-sub
    ans+=app
    sub+=app

print(ans)

Submission status: Wrong Answer

Solution code:
def main():

    n, m = map(int, input().split())
    relations = {}
    for i in range(m):
        nums = list(map(int, input().split()))
        nums.sort()
        if nums[0] not in relations:
            relations[nums[0]] = [nums[1]]
        elif nums[1] not in relations[nums[0]]:
            relations[nums[0]].append(nums[1])
    ans = 0
    for key in relations:
        ans = max(len(relations[key]), ans)

    print(ans + 1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter


def main():
    stdin = sys.stdin
    n, m = map(int, stdin.readline().split())
    ls= []
    for _ in range(m):
        a, b = map(int, stdin.readline().split())
        if a > b:
            ls.append((b,a))
        else:
            ls.append((a,b))
    ls.sort(key= lambda x: x[0])
    ls2 = [i for i in range(n)]

    for a, b in ls:
        ls2[b-1] = ls2[a-1]

    print(Counter(ls2).most_common()[0][1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(SOLVE_PARAMS):
    pass


def main():
    N, M = map(int, input().split())
    is_head = [True] * N
    from collections import defaultdict
    edges = defaultdict(list)
    for q in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        is_head[b] = False
        edges[a].append(b)

    to_tail = [-1] * N
    visited = [False] * N

    def dfs(x):
        buf = [0]
        visited[x] = True
        for v in edges[x]:
            if visited[v]:
                continue
            ret = to_tail[v]
            if ret == -1:
                ret = dfs(v)
                to_tail[v] = ret
            buf.append(ret)
        return max(buf) + 1

    buf = [1]
    for i in range(N):
        visited = [False] * N
        buf.append(dfs(i))

    # debug(": to_tail", to_tail)
    print(max(buf))


# tests
T1 = """
5 3
1 2
3 4
5 1
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
3
"""

T2 = """
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
4
"""

T3 = """
10 4
3 1
4 1
5 9
2 6
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
3
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()

Submission status: Wrong Answer

Solution code:
n,m = [int(i) for i in input().split()]
d = []
for i in range(m):
  d.append(sorted([int(i) for i in input().split()]))
#
  #d.append(sorted([      #int(i) for i in input().split()]))
d.sort()
#print(sorted(d))

groups = list(range(n))
for t1,t2 in d:
  groups[t2-1] = groups[t1-1]
#print(groups)
groups.sort()

g = [0 for _ in range(len(groups))]
for i in groups:
  g[i] += 1
print(max(g))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]
from collections import deque
e = [list() for _ in range(n)]
for i in range(m):
    e[ab[i][0]-1] += [ab[i][1]-1]
    e[ab[i][1]-1] += [ab[i][0]-1]

stack = deque()
visited = [0]*n
group = [0]*n

def dfs(x):
    num = 0
    stack.append(x)
    while stack:
        v = stack.pop()
        for k in e[v]:
            if visited[k]==0:
                num +=1
                visited[k]=1
                stack.append(k)
    return num


li = []

for i in range(n):
    li += [dfs(i)]

print(max(li))

Submission status: Wrong Answer

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

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

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

print(max([len(s) for s in friends_set])+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
flist = []
ans = 0
for i in range(n):
  flist.append([i+1])
for j in range(m):
  a,b = map(int,input().split())
  MIN = min(a,b)
  MAX = max(a,b)
  flist[MIN-1].append(MAX)
for i in range(n):
  flist[i] = set(flist[i])
  score = len(flist[i])
  if ans < score:
    ans = score
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
all_set = set({})
friends = []
ans = 1
for i in range(m):
    t1, t2 = map(int, input().split())
    if t1 in all_set or t2 in all_set:
        for j in range(len(friends)):
            if t1 in friends[j] or t2 in friends[j]:
                friends[j] = friends[j] | {t1, t2}
                if len(friends[j]) > ans:
                    ans = len(friends[j])
                break
    else:
        friends.append({t1, t2})
    all_set = all_set | {t1, t2}

print(ans)

Submission status: Wrong Answer

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

grpno=[i for i in range(N)]
ngrp=[1 for i in range(N)]
members=[[i] for i in range(N)]


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

    if p > q:
        r = p
        p = q
        q = r
    
    if grpno[p-1] != grpno[q-1]:
        ngrp[grpno[p-1]] += ngrp[grpno[q-1]]
        ngrp[grpno[q-1]] = 0
        grpno[q-1]=grpno[p-1]
   
        members[p-1] += members[q-1]

# for i in range(N):
#     print("i=",i)
#     print(members[i])
#     print("group_no=",grpno[i])
#     print("#member=",ngrp[i])

print(max(ngrp))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
groups = [set(map(int, input().split())) for _ in range(M)]
new = []
ans = 1
already = set()
if M > 0:
    ans = 2

for i in range(len(groups)):
    if groups[i].isdisjoint(already):
        new.append(groups[i])
    else:
        for j in range(len(new)):
            if not new[j].isdisjoint(groups[i]):
                new[j] |= groups[i]
                break
    already |= groups[i]

for i in new:
    ans = max(ans, len(i))

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
edge = []
for i in range(M):
    a,b = map(int,input().split())
    add = []
    for j in range(len(edge)):
        if a in edge[j] or b in edge[j]:
            edge[j].append(a)
            edge[j].append(b)
            add.append(j)
    if len(add) == 0:
        edge.append([a,b])
    elif len(add) >= 2:
        for j in range(1,len(add)):
            edge[add[0]].extend(edge[add[j]])
        for j in range(1,len(add)):
            edge.pop(add[j])
ans = 0
for i in range(len(edge)):
    x = list(set(edge[i]))
    if len(x) > ans:
        ans = len(x)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
group = []
for _ in range(M):
  A, B = map(int, input().split())
  for g in group:
    if A in g or B in g:
      g.add(A)
      g.add(B)
      break
  else:
    group.append(set((A, B)))

# print(group)

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n,m = map(int,input().split())
flist = list()
for i in range(m):
  flist.append(list(map(int,input().split())))
G = defaultdict(set)
ret = 0
for f in flist:
    if len(G.keys())== 0:
        G[f[0]].add(f[0])
        G[f[0]].add(f[1])
        ret = len(G[f[0]])
    else:
        for i in range(len(G.keys())):
            tmp_ = list(G.keys())[i]
            if f[0] in G[tmp_] or f[1] in G[tmp_]:
                G[tmp_].add(f[0])
                G[tmp_].add(f[1])
                ret = max(len(G[tmp_]),ret)
                break
            elif i == len(G.keys()) - 1:
                G[f[0]].add(f[0])
                G[f[0]].add(f[1])
                ret = max(len(G[f[0]]),ret)

print(ret)

Submission status: Wrong Answer

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


def main():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        graph[a - 1].append(b - 1)
        graph[b - 1].append(a - 1)
    ans = 0
    for i in range(N):
        cnt = len(collections.Counter(graph[i]))
        ans = max(ans, cnt)
    print(ans + 1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n, m = [int(i) for i in input().split()]
people = [-1] * n
num = 1
ab = [0] * m

for i in range(m):
    ab[i] = sorted([int(i) for i in input().split()])

ab.sort()

for a, b in ab:
    a -= 1
    b -= 1
    if people[a] == -1 and people[b] == -1:
        people[a] = num
        people[b] = num
        num += 1
    elif people[a] == -1 or people[b] == -1:
        if people[a] == -1: people[a] = people[b]
        else: people[b] = people[a]

print(max(Counter(people).values()))

Submission status: Wrong Answer

Solution code:
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

n,m = rm()
a = []
for i in range(m):
    a.append(rl())
b = defaultdict(int)
c = defaultdict(int)
visi = defaultdict(int)

for i in a:
    mi, ma = min(i[0], i[1]), max(i[0], i[1])
    if visi[(mi,ma)]==1:
        continue
    visi[(mi,ma)]=1
    if c[i[0]]==0 and c[i[1]]==0:
        c[i[0]]=i[0]
        c[i[1]]=i[0]
        b[i[0]]+=1
    elif c[i[0]]==0:
        c[i[0]]=c[i[1]]
        b[c[i[1]]]+=1
    elif c[i[1]]==0:
        c[i[1]]=c[i[0]]
        b[c[i[0]]]+=1
    elif c[c[i[0]]]!=c[c[i[1]]]:
        if b[c[c[i[0]]]]>b[c[c[i[1]]]]:
            b[c[c[i[0]]]]+=b[c[c[i[1]]]]+1
            b[c[c[i[1]]]]=0
            c[c[i[1]]]=c[c[i[0]]]
        else:
            b[c[c[i[1]]]]+=b[c[c[i[0]]]]+1
            b[c[c[i[0]]]]=0
            c[c[i[0]]]=c[c[i[1]]]

maxi = 0
for i in b.keys():
    maxi = max(maxi, b[i])

print(maxi+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
friends = dict()
if M == 0:
    print(0)
    exit(0)
for i in range(M):
    a, b = map(int, input().split())
    if friends.get(a) is None:
        friends[a] = set([b])
    else:
        friends[a].add(b)
    if friends.get(b) is None:
        friends[b] = set([a])
    else:
        friends[b].add(a)
# for f in friends.values():
#     print(f)
#     print(len(f))

ans = max([len(a) for a in friends.values()]) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N, M = map(int, input().split())
# AB = [list(map(int, input().split())) for _ in range(M)]

AB = []
lst = [0] * (N + 1)

c = 0
for _ in range(M):
    a, b = map(int, input().split())
    if b < a:
        a, b = b, a

    AB.append((a, b))

AB.sort(key=lambda x: (x[0], x[1]))

for a, b in AB:

    if lst[a] == 0:
        c += 1

    lst[a] = c
    lst[b] = c


counter = Counter(lst[1:])
max_ = 0
for v in counter.values():
    max_ = max(max_, v)

print(max_)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
l = [i for i in range(N)]
m = [0 for i in range(N)]
for i in range(M):
    A,B = map(int,input().split())
    if l[A-1] > l[B-1]:
        l[A-1] = l[B-1]
        m[l[B-1]] += 1
    elif l[A-1] < l[B-1]:
        l[B-1] = l[A-1]
        m[l[A-1]] += 1
print(max(m)+1)

Submission status: Wrong Answer

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

# print(AB)

class UnionFind: # with rank
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x: return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]
    def union(self, x, y):
        x = self.find(x); y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

uf = UnionFind(n)
for a, b in AB:
    uf.union(a, b)
# for v in range(1,n+1):
#     print('find(v) {}'.format(uf.find(v)))
# print('uf {}'.format(uf.par))

m = {}
for g in uf.par:
    if not g in m:
        m[g] = 0
    m[g] += 1

# print(m)

ans = 0

for k,v in m.items():
    if k == 0: continue
    # print(k,v)
    if ans < v:
        ans = v

print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    n, m = map(int, input().split())
    group = []
    done = [-1]*n
    num = 0
    for i in range(m):
        a, b = map(lambda x:int(x)-1, input().split())
        if done[a] != -1:
            if done[b] == -1:
                group[done[a]].append(b)
                done[b] = done[a]
        else:
            if done[b] == -1:
                group.append([a,b])
                done[a], done[b] = num, num
                num += 1
            else:
                group[done[b]].append(a)
                done[a] = done[b]
    people = [0]+sorted([len(i) for i in group])
    ans = 0
    for i in range(1,len(people)):
        ans += people[i]-people[i-1]
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
fri_dic = {}
for _ in range(m):
  a, b = map(int, input().split())
  if a not in fri_dic:
    fri_dic[a] = set()
  if b not in fri_dic[a]:
    fri_dic[a].add(b)
  if b not in fri_dic:
    fri_dic[b] = set()
  if a not in fri_dic[b]:
    fri_dic[b].add(a)
visited = set()
count = 0
for i in range(1, n + 1):
  #print(visited)
  if i in visited:
    continue
  queue = [i]
  con_visited = set()
  while queue:
    p = queue.pop(0)
    if p in visited:
      continue
    visited.add(p)
    con_visited.add(p)
    if p not in fri_dic:
      continue
    for j in fri_dic[p]:
      queue.append(j)
  if len(con_visited) > 2:
    count += len(con_visited)
if count == 0:
  if m == 0:
    count = 1
  else:
    count = 2
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

# from typing import Optional
# from typing import List
# from typing import Dict
# from typing import Tuple
# from typing import Sequence


def main():
    args = input().split()
    N = int(args[0])
    M = int(args[1])

    groupList = list()
    for i in range(M):
        args = list(map(lambda x: int(x), input().split()))

        isHit = False
        for group in groupList:
            if args[0] in group:
                group.add(args[1])
                isHit = True
            elif args[1] in group:
                group.add(args[0])
                isHit = True

        if not isHit:
            groupList.append({args[0], args[1]})

    maxNum = 0
    for group in groupList:
        maxNum = max(maxNum, len(group))

    print(maxNum)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
g = [set() for i in range(n)]
for i in range(m):
    a,b =map(int, input().split())
    a-=1
    b-=1
    for j in g[a]:
        if j == b:
            continue
        g[j].add(b)
    for j in g[b]:
        if j == a:
            continue
        g[j].add(a)
    g[a].add(b)
    g[b].add(a)
maxlen = 0
for i in range(n):
    maxlen = max(maxlen,len(g[i]))
print(maxlen+1)

Submission status: Wrong Answer

Solution code:
import collections
def solve():
  N,M = map(int,input().split())
  ABlist = [[0,0] for _ in range(M)]
  WA = [0]*N
  for i in range(N):
    WA[i] = i+1
  for i in range(M):
    A, B = map(int,input().split())
    if A>B:
      A,B =B,A
    ABlist[i][0] = A
    ABlist[i][1] = B
  ABlist.sort()
  for i in range(M):
    A = ABlist[i][0]
    B = ABlist[i][1]
    WA[B-1] = WA[A-1]
  c = collections.Counter(WA)
  print(c.most_common()[0][1])
solve()

Submission status: Wrong Answer

Solution code:
nm = input('').split()
n = int(nm[0])
m = int(nm[1])

friends={}
for i in range(m):
    ab=input('').split()
    a = ab[0]
    b = ab[1]
    if a not in friends.keys():
        friends[a]=set()
    if b not in friends.keys():
        friends[b]=set()
    friends[a].add(b)
    friends[b].add(a)
    for a2 in friends[a]:
        friends[a2].add(b)
    for b2 in friends[b]:
        friends[b2].add(a)

mx=0
for k,v in friends.items():
#    print("{}:{}".format(k,v))
    len_v=len(v)
    if len_v>mx:
        mx=len_v
print(mx)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
L=[0]*(N+1)
temp=set()
for i in range(M):
  A,B=map(int,input().split())
  if A>B:
    A,B=B,A
  if (A,B) in temp:
    continue
  else:
    temp.add((A,B))
    L[A]+=1
    L[B]+=1
print(max(L)+1)

Submission status: Wrong Answer

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

G = []
m = {}
for _ in range(M):
    a, b = map(int, input().split())
    if a in m and b in m:
        continue
    elif a in m:  # b not in m
        gid = m[a]
        m[b] = gid
        G[gid].add(b)
    elif b in m:  # a not in m
        gid = m[b]
        m[a] = gid
        G[gid].add(a)
    else:
        G.append({a, b})
        m[a] = len(G) - 1
        m[b] = len(G) - 1

if G:
    print(max([len(g) for g in G]))
else:
    print(1)

Submission status: Wrong Answer

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

friends = [0] * n
query = []

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

for i in range(m):
  a,b = map(int, input().split())
  if a > b:
    query.append((b, a))
  else:
    query.append((a,b))

good_query = list(map(list, set(map(tuple, query))))
for i in good_query:
  friends[i[0] - 1] += 1
  friends[i[1] - 1] += 1

print(max(friends)+1)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m = map(int, input().split())
friend = [set() for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  friend[a-1].add(b-1)
  friend[b-1].add(a-1)

flag = [True for i in range(n)]
max_grupe = 0
for i in range(n):
  if(flag[i] == False):
    break
  num = 0
  queue = deque([i])
  flag[i] = False
  while queue:
    now = queue.popleft()
    num += 1
    flag[now] = False
    for j in friend[now]:
      if(flag[j]):
        queue.append(j)
        flag[j] = False
        
  max_grupe = max(max_grupe, num)
  
print(max_grupe)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    n, m = map(int, input().split())
    li = {}
    if m == 0:
        print(1)
        return

    for _ in range(m):
        a, b = sorted(map(int, input().split()))
        if a not in li:
            li[a] = {b}
        else:
            li[a].add(b)
    i = max(li, key=lambda k: len(li[k]))
    print(len(li[i]) + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

members = np.array([-1] * N).astype(np.int)

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]:
            groups[members[A]] += groups[members[B]]
            groups[members[B]] = 0
            members[group_dict[members[B]]] = members[A]


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

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
G = [[] for i in range(n)]
C = [[]for i in range(n)]
for _ in range(m):
    A, B = map(int, input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)
ans = 0
for i in range(len(G)):
    ans = max(len(set(G[i])),ans)
print(ans +1)

Submission status: Wrong Answer

Solution code:
import collections

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parent = [i for i in range(self.n)]
    self.rank = [0] * self.n
  
  def find_root(self, x):
    if self.parent[x] == x:
      return x
    else:
      self.parent[x] = self.find_root(self.parent[x])
      return self.parent[x]
  
  def unite(self, x, y):
    rx = self.find_root(x)
    ry = self.find_root(y)
    if rx == ry:
      return
    if self.rank[rx] < self.rank[ry]:
      self.parent[rx] = ry
    else:
      self.parent[ry] = rx
      if self.rank[rx] == self.rank[ry]:
        self.rank[rx] += 1
  
  def is_same(self, x, y):
    return self.find_root(x) == self.find_root(y)

N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
  A, B = map(lambda x: int(x)-1, input().split())
  uf.unite(A, B)

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

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
edges = [[] for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
#print(edges)

le = len(edges)
cnt = 0
for i in range(le):
  cnt = max(cnt,len(set(edges[i])))
print(cnt+1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    from collections import deque

    N, M = map(int, input().split())
    friends_input = [set() for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        friends_input[a - 1].add(b - 1)
        friends_input[b - 1].add(a - 1)

    seen = [False] * N
    friends_group = []
    for i in range(N):
        if seen[i]:
            continue
        q = deque([i])
        tmp_group = [i]
        while q:
            now = q.popleft()
            if seen[now]:
                continue
            seen[now] = True
            for j in friends_input[now]:
                if not seen[j]:
                    q.append(j)
                    tmp_group.append(j)
        friends_group.append(tmp_group)
    ans = 0
    for i in friends_group:
        ans = max(ans, len(i))
    print(ans)
    print(friends_group)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from copy import deepcopy


def main():
    n, m = map(int, input().split())
    groups = [None] * n
    groups_member = []
    num_groups = 0
    for i in range(m):
        a, b = map(int, input().split())
        if groups[a - 1] is None and groups[b - 1] is None:
            groups[a - 1] = num_groups
            groups[b - 1] = num_groups
            groups_member.append(set([a-1, b-1]))
            num_groups += 1
        elif groups[a - 1] is None:
            groups[a - 1] = groups[b - 1]
            groups_member[groups[b - 1]].add(a - 1)
        elif groups[b - 1] is None:
            groups[b - 1] = groups[a - 1]
            groups_member[groups[a- 1]].add(b - 1)
        else:
            tmp = groups[b - 1]
            for j in groups_member[tmp]:
                groups[j] = groups[a - 1]
            _tmp = deepcopy(groups_member[tmp])
            groups_member[tmp] |= set(groups_member[groups[a - 1]])
            groups_member[groups[a - 1]] |= set(_tmp)
        # print(groups)
        # print(groups_member)
    
    max_people = 0
    for m in groups_member:
        if max_people < len(m):
            max_people = len(m)
    print(max_people)
    # print(groups)
    # print(groups_member)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys


def main():
    N,M = list(map(int, sys.stdin.readline().split()))
    AB_list = [ list(map(int, sys.stdin.readline().split())) for _ in range(M) ]


    edge = {}  
    # { int : set }
    # { the number of human : {friends} }

    for a,b in AB_list:
        edge.setdefault(a, set())
        edge[a].add(b)

        edge.setdefault(b, set())
        edge[b].add(a)
    

    max_relation = 0

    for k in edge:
        max_relation = max( max_relation, len( edge[k] ) )
    
    
    print( max_relation + 1 )


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

n,m=map(int,input().split())
f=[[] for i in range(n)]
check=[False for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    f[a].append(b)
    f[b].append(a)
ans=0
for i in range(n):
    if check[i]:
        continue
    else:
        tmp=1
        check[i]=True
        if len(f[i])==0:
            continue
        d=deque()
        d.append(i)
        while d:
            v=d.popleft()
            for j in f[i]:
                if check[j]:
                    continue
                check[j]=True
                tmp+=1
                d.append(j)
        ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
c = list(map(list, set(map(tuple, [sorted(list(map(int, input().split()))) for i in range(M)]))))

g = [0]*N
n = [0]*N

num = 1

for i in range(len(c)):
    
    if g[c[i][0]-1] != 0 and g[c[i][1]-1] != 0:
        pass
    elif g[c[i][0]-1] != 0:
        g[c[i][1]-1] = g[c[i][0]-1]
        n[g[c[i][0]-1]-1] += 1
    elif g[c[i][1]-1] != 0:
        g[c[i][0]-1] = g[c[i][1]-1]
        n[g[c[i][1]-1]-1] += 1
    else:
        g[c[i][0]-1] = num
        g[c[i][1]-1] = num
        n[num-1] += 2
        num += 1

print(max(n) or 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    people_count, info_count = [int(x) for x in input().split()]
    if info_count == 0:
        return 1
    if info_count == 1:
        return 2

    frieds_circle_ids = [-1] * people_count
    new_id = 0
    for _ in range(info_count):
        a, b = [int(x) - 1 for x in input().split()]
        id_a = frieds_circle_ids[a]
        id_b = frieds_circle_ids[b]
        new_id += 1
        if id_a == -1 == id_b:
            frieds_circle_ids[a] = new_id
            frieds_circle_ids[b] = new_id
        elif id_a == -1:
            frieds_circle_ids[a] = id_b
        elif id_b == -1:
            frieds_circle_ids[b] = id_a
    return Counter(frieds_circle_ids).most_common()[0][1]


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
def main():

    n,m = map(int,input().split())
    ary = []
    for i in range(m):
        aa, bb = map(int,input().split())
        l = min(aa,bb)-1
        r = max(aa,bb)-1
        ary.append((l,r))
    ary_s = list(set(ary))
    a = []
    # b = []
    # Union-Find作る
    uf = UnionFind(n)

    for i in range(len(ary_s)):
        a.append(ary_s[i][0])
        a.append(ary_s[i][1])
        uf.union(ary_s[i][0], ary_s[i][1])
    ans = 0
    for i in a:
        ans = max(ans, uf.size(i))
    print(ans)

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

if __name__=='__main__':
    main()