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())
F = [0] * n
B = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int, input().split())
    if b not in B[a-1]:
        B[a-1].append(b)
        F[a - 1] += 1
    if a not in B[b-1]:
        B[b-1].append(a)
        F[b - 1] += 1

count = max(F)
print(count + 1)

Submission status: Wrong Answer

Solution code:

def resolve():
  N, M = map(int, input().split(" "))
  checked = [False] * (N + 1)
  # frend_labels = [0] * (N + 1)
  # frend_labels_counter = [0] * (N + 1)
  num_of_friend = [0] * (N + 1)
  friends = []
  for _ in range(N+1):
    friends.append(set())

  maximam_friends = 0
  for _ in range(M):
    A, B = map(int, input().split(" "))
    friends[A].add(B)
    friends[B].add(A)
    union = friends[A] | friends[B]
    friends[A] = union
    friends[B] = union

    if num_of_friend[A] == 0 and num_of_friend[B] == 0:
      num_of_friend[A] += 1
      num_of_friend[B] += 1
    elif num_of_friend[A] == 0:
      num_of_friend[B] += 1
      for friend in friends[B]:
        num_of_friend[friend] = num_of_friend[B]
    elif num_of_friend[B] == 0:
      num_of_friend[B] = num_of_friend[A]
      num_of_friend[A] += 1
      for friend in friends[A]:
        num_of_friend[friend] = num_of_friend[A]

    if num_of_friend[A] > maximam_friends:
      maximam_friends = num_of_friend[A]

  # for friend in friends:
  #   print(friend)
  print(maximam_friends+1)

if __name__ == "__main__":
  resolve()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A_B = []
for _ in range(M):
    a_b = list(map(int, input().split()))
    A_B.append(a_b)

friend_list = [[] for _ in range(N)]

for a, b in A_B:
    for i in range(N):
        if not friend_list[i]:
            friend_list[i].append(a)
            friend_list[i].append(b)
            break
        else:
            if a in friend_list[i]:
                if b not in friend_list[i]:
                    friend_list[i].append(b)
                break
            if b in friend_list[i]:
                if a not in friend_list[i]:
                    friend_list[i].append(a)
                break

ans = 0
for friend in friend_list:
    len_friend = len(friend)
    ans = max(ans, len_friend)
print(ans)

Submission status: Wrong Answer

Solution code:
m,n=map(int,input().split())
a_list=[i+1 for i in range(m)]
m_list=[]
for i in range(n) :
  a,b = map(int, input().split())
  if a<b :
    m_list.append(str(a)+' '+str(b))
  else :
    m_list.append(str(b) +' '+ str(a))

m_list=list(set(m_list))
n1=len(m_list)
s_list=[]
for i in m_list :
  s_list.append(list(map(int, i.split())))

s_list=sorted(s_list,key=lambda x: x[0])





for s in s_list :
  a_list[s[1]-1]=a_list[s[0]-1]
import collections
c = collections.Counter(a_list)


print(max(list(c.values())))

Submission status: Wrong Answer

Solution code:
n=list(map(int, input().split()))
kankei=[[]]*(n[0]+1)
group=[1]*(n[0]+1)
for i in range(n[1]):
    j = list(map(int, input().split()))
    j1=max(j)
    j2=min(j)
    if j1 not in kankei[j2]:
        kankei[j2].append(j1)
        group[j2]+=1
        group[j1]+=1
print(max(group))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = [[0]]

for i in range(m):
    a, b = map(int, input().split())
    for j in range(len(l)):
        if a in l[j]:
            l[j].append(b)
        elif b in l[j]:
            l[j].append(a)
        else:
            l.append([a, b])

cnt = []
for i in range(len(l)):
    cnt.append(len(l[i]))

print(max(cnt))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
x = []
y = []

for i in range(M):
  a, b = map(int, input().split())
  if a in x:
    for j in y:
      if a in j:
        j.append(b)
  else:
    y.append([a])
  if b in x:
    for j in y:
      if b in j:
        j.append(a)
  else:
    y.append([b])
  x.append(a)
  x.append(b)

n = 0

for i in y:
  if len(i)>n:
    n = len(i)
    
print(n)

Submission status: Wrong Answer

Solution code:
n, m = [int(e) for e in input().split()]

d = {}

for i in range(m):
    a, b = [int(e) for e in input().split()]
    
    if a > b:
        a, b = b, a

    if not a in d:
        d[a] = set([a])
    if not b in d:
        d[b] = set([b])    

    if len(d[a]) > len(d[b]):
        d[a].update(d[b])
        d[b] = d[a]
        d[a].add(b)
    else:
        d[b].update(d[a])
        d[a] = d[b]
        d[b].add(a)

r = 1
for v in d.values():
    if len(v) > r:
        r = len(v)

print(r)

Submission status: Wrong Answer

Solution code:
import collections

from collections import deque

n,m=map(int,input().split())
f=[[] for i in range(n)]
flist=[]
check=[False for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    flist.append([a,b])
    f[a].append(b)
    f[b].append(a)
ans=1
for i in range(n):
    if check[i]:
        continue
    else:
        d=deque()
        check[i]=True
        d.append(i)
        tmp=1
        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)



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

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

Submission status: Wrong Answer

Solution code:
import sys

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

n, m = map(int, readline().split())
ab = map(int, read().split())


def f(n, m, ab):
    graph = [[] for _ in range(n+1)]
    for a, b in zip(ab, ab):
        if b in graph[a]:
            continue
        else:
            graph[a].append(b)
        if a in graph[b]:
            continue
        else:
            graph[b].append(a)

    max_cnt = 0

    for i in range(len(graph)):
        cnt = len(graph[i])
        if cnt > max_cnt:
            max_cnt = cnt
    
    return max_cnt


print(f(n, m, ab) + 1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
li=[]
for i in range(m):
    a,b=map(int,input().split())
    if len(li)==0:
        li.append([a,b])
    else:
        flag=0
        for j in range(len(li)):
            if a in li[j] and b not in li[j]:
                li[j].append(b)
                flag=1
            elif a not in li[j] and b in li[j]:
                li[j].append(a)
                flag=1
            elif flag==0 and j==len(li)-1:
                li.append([a,b])
    #print(li)
ans=0
for i in range(len(li)):
    if len(li[i])>ans:
        ans=len(li[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


N,M = LI()
AB = [LI() for _ in range(M)]
# A,B = zip(*AB)
# print(A)
# Ap = np.array(A)
ans = 0

# 無向グラフ
G = []
for _ in [0]*N:
    G.append([False]*N)

for r in AB:
    f = r[0]-1
    t = r[1]-1
    G[f][t] = True
    G[t][f] = True

# print(G)

used = [False] * N

ss = []
for i in range(N):
    if used[i]==True:
        continue
    used[i]=True
    s = set([i])
    l = [i for i, x in enumerate(G[i]) if x == True]
    # print(l)
    for j in l:
        used[j]=True
        s.add(j)
        for i,x in enumerate(G[i]):
            if x == True and used[i]==False:
                s.add(i)
    ss.append(s)
# print(ss)

print(len(max(ss)))

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]+[len(i) for i in group]
    amari = done.count(-1)
    ans = max(people)
    if sum(people) > amari:
        print(ans)
    else:
        print(amari-ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def dfs(node):
    if node in visited:
        return False
    visited.add(node)
    for neighbor in adj_list[node]:
        dfs(neighbor)
    return True

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)
    visited.add(a)
    visited.add(b)

#for node in range(1, N+1):
#    if dfs(node):
#        count += 1

print(max(map(lambda x: len(x)+1, adj_list.values())) if adj_list else 1)

Submission status: Wrong Answer

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)
    else:
      G[ai].add(bi)
  elif bi in G:
    if type(G[bi]) is int:
      G[G[bi]].add(ai)
    else:
      G[bi].add(ai)
  else:
    G[ai] = {ai, bi}
    G[bi] = ai
ans = 0
for i in G:
  if type(G[i]) is not int:
    if len(G[i]) > ans:
      ans = len(G[i])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

f=[]
for i in range(n+1):
    f.append(set())


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

    fa=f[a]
    f[a].add(b)
    f[a] = f[a] | f[b]  
    
    f[b].add(a)
    fb = f[b] | fa


cm=0
for i in range(n+1):
    f[i].discard(i)
    if cm < len(f[i])+1:
        cm = len(f[i])+1
print(cm)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

def dfs(human, ignore):
    res = {human}
    n_ignore = {i for i in ignore}
    for i in r[human]:
        n_ignore.add(i)
    for n_human in r[human]:
        if n_human in ignore:
            continue
        for i in dfs(n_human, n_ignore):
            res.add(i)
    return res

n, m = MAP()
r = [set() for _ in range(n)]
for _ in range(m):
    a, b = MAP()
    a -= 1
    b -= 1
    if b < a:
        a, b = b, a
    r[a].add(b)
#print(r)
ans = 1
ans_set = set()
for i in range(n):
    if i in ans_set:
        continue
    tmp = dfs(i, set())
    #print(i, tmp)
    ans = max(ans, len(tmp))
    for j in tmp:
        ans_set.add(j)
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=list(map(int, input().split()))
a=[]
b=[]
for j in range(m):
    a1,b1=[int(j) for j in input().split()]
    a.append(a1)
    b.append(b1)
d=[0]*n
e=[0]*n
for q in range(n):
    d[q]=q


for i in range(m):
    x=min(a[i],b[i])-1
    y=max(a[i],b[i])-1
    z=x
    while z!=d[z]:
        z=d[z]
    d[y]=z
for j in range(n):
    p=d[j]
    e[p]+=1
print(max(e))

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])
        nums.reverse()
        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(relations)
    print(ans + 1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

group_dict = defaultdict(lambda : None)
group_counter = 0
group_member = [0]*(n+1)

update_dict = defaultdict(lambda : None)

group = []
for i in range(m):
    a,b = friend_list[i]

    a_group = group_dict[a]
    b_group = group_dict[b]
    target_group = -1
    if a_group != None:
        target_group = a_group
    if b_group != None:
        target_group = b_group

    if target_group == -1:
        target_group = group_counter
        group_counter+=1

    if a_group != None and b_group != None:
        target_group = max(a_group,b_group)
        update_dict[min(a_group,b_group)] = max(a_group,b_group)
    
    group_dict[a] = target_group
    group_dict[b] = target_group


for k in group_dict:

    new_k = update_dict[group_dict[k]]
    prev = None
    while prev != new_k and new_k != None:
        prev = new_k
        new_k = update_dict[new_k]
    if prev != None:
        change = prev
    else:
        change = group_dict[k]
    group_member[change] += 1

print(max(group_member))

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
I = [-1] * (n+1)
x = [[]]
for _ in range(m):
    a,b = map(int, input().split())
    if a==b: continue
    if x == [[]]:
        x[0] += [a,b]
        I[a]=I[b]=0
    else:
        if I[a]!=-1 and I[b] == -1:
            x[I[a]].append(b)
            I[b] = I[a]
        elif I[b] != -1 and I[a] == -1:
            x[I[b]].append(a)
            I[a] = I[b]
        elif I[b] == -1 and I[a] == -1:
            x.append([a,b])
            I[a]=I[b]=len(x)-1
ans = 0
for i in x:
    ans = max(ans, len(i))
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N,M = map(int,input().split())
    A = [[0,0] for i in range(M)]
    for i in range(M):
        A[i] = list(map(int,input().split()))
        list.sort(A[i])
    
    list.sort(A)
    
    List = [-1 for i in range(N)]
    host = 0
    for i in range(M):
        a = A[i][0]-1
        b = A[i][1]-1
        if List[a] == -1:
            host = a
        else:
            host = List[a]
        List[b] = host
        
    ans = [0 for i in range(N)]
    for i in range(N):
        L = List[i]
        if L != -1:
            ans[L] += 1
            
    print(max(ans)+1)
        
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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)
    else:
      G[ai].add(bi)
  elif bi in G:
    if type(G[bi]) is int:
      G[G[bi]].add(ai)
    else:
      G[bi].add(ai)
  else:
    G[ai] = {ai, bi}
    G[bi] = ai
ans = 0
for i in G:
  if type(G[i]) is not int:
    if len(G[i]) > ans:
      print(G[i])
      ans = len(G[i])
print(ans)

Submission status: Wrong Answer

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

friend = [set() for _ in range(N)]

for _ in range(M):
    A, B = map(int, input().split())

    tmp = list(friend[A-1])
    if len(tmp) > 0 and (not B-1 in tmp):
        for i in range(len(tmp)):
            var = tmp[i]
            if var != B-1:
                friend[var].add(B-1)
                friend[B-1].add(var)
    friend[A-1].add(B-1)

    tmp = list(friend[B-1])
    if len(tmp) > 0 and (not A-1 in tmp):
        for i in range(len(tmp)):
            var = tmp[i]
            if var != A-1:
                friend[var].add(A-1)
                friend[A-1].add(var)
    friend[B-1].add(A-1)

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

Submission status: Wrong Answer

Solution code:
import copy
import sys
from collections import deque
N, M = map(int,input().split())
checked = [False] * N
dq = deque([0])
path = [[] for _ in range(N)]
for s in sys.stdin.readlines():
    a, b = list(map(lambda x: int(x)-1, s.split()))
    path[a].append(b)
    path[b].append(a)
ans = 1
dq = deque([[i,1] for i in range(N)])
while dq:
   i, d= dq.popleft()
   if checked[i]:
      continue
   checked[i] = True
   d += 1
   for j in range(len(path[i])):
      h = path[i][j]
      if not checked[h]:
         dq.append([h, d])
   ans = max(d, ans)
print(ans)

Submission status: Wrong Answer

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

ab = []
for a, b in ab_:
    ab.append([a-1, b-1])

g_idx = [0] * n
g_sum = [0] * n
mrg = []

i = 1

def get_idx(i :int):
    for g_f, g_t in mrg:
        if g_f == i:
            i = g_t
    return i

for a, b in ab:
    if not g_idx[a] and not g_idx[b]:
        g_idx[a] = i
        g_idx[b] = i
        g_sum[i] += 2
        i += 1
    elif g_idx[a] and not g_idx[b]:
        idx = get_idx(g_idx[a])
        g_idx[b] = idx
        g_sum[idx] += 1
    elif g_idx[b] and not g_idx[a]:
        idx = get_idx(g_idx[b])
        g_idx[a] = idx
        g_sum[idx] += 1
    else:
        idx_a = get_idx(g_idx[a])
        idx_b = get_idx(g_idx[b])
        sum_a = g_sum[idx_a]
        sum_b = g_sum[idx_b]
        if sum_a >= sum_b:
            g_sum[idx_b] = 0
            g_sum[idx_a] += sum_b
            mrg.append([idx_b, idx_a])
        else:
            g_sum[idx_a] = 0
            g_sum[idx_b] += sum_a
            mrg.append([idx_a, idx_b])

mx = 0
for s in g_sum:
    if s > mx:
        mx = s

print(mx)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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)


print(N + 1)

Submission status: Wrong Answer

Solution code:
import copy

n,m = map(int,input().split())
f = []

for i in range(m):
    a,b=map(int,input().split())
    flg = True
    for j in f:
        if a in j:
            j.add(b)
            flg = False
        elif b in j:
            j.add(a)
            flg = False

    if flg:
        f.append({a,b})

nf = copy.deepcopy(f)

for i in f:
    for j in i:
        for k in f:
            if j in k:
                nf.append(i|k)

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


print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
class DSU:
    def __init__(self, N):
        self.p = [i for i in range(0, N + 1)]

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

    def union(self, x, y):
        xp = self.find(x)
        yp = self.find(y)
        if xp != yp:
            if xp < yp:
                xp, yp = yp, xp
            self.p[xp] = yp

N, C = list(map(int, input().split()))
dsu = DSU(N)
for _ in range(C):
    x, y = list(map(int, input().split()))
    dsu.union(x, y)
c = Counter(dsu.p)
for _, v in sorted(c.items(), key = lambda x: -1*x[1]):
    print(v)
    break

Submission status: Wrong Answer

Solution code:
class Solution:
    def find_root(self, A, parent):
        if parent[A] == A:
            return A
        return self.find_root(parent[A], parent)

    def union(self, A, B, parent, height):
        C = self.find_root(A, parent)
        D = self.find_root(B, parent)

        if C == D:
            return

        if height[C] < height[D]:
            parent[C] = D

        elif height[C] > height[D]:
            parent[D] = C

        else:
            parent[D] = C
            height[C] += 1

    def solve(self, A, N):
        cnt = 0
        parent = [i for i in range(N)]
        height = [0 for _ in range(N)]
        for i, j in A:
            C = self.find_root(i-1, parent)
            D = self.find_root(j-1, parent)

            if C == D:
                continue

            self.union(C, D, parent, height)
            cnt += 1

        return cnt

if __name__ == '__main__':
    N, M = map(int, input().split())
    A = []
    for _ in range(M):
        p,q = map(int, input().split())
        A.append([p,q])
    B = Solution()
    print(B.solve(A, N))

Submission status: Wrong Answer

Solution code:
import sys
from  collections import Counter

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

friends = []

if M==0:
    print(1)
    sys.exit()

for _ in range(M):
    A_i, B_i = map(int, input().split())
    if A_i > B_i:
        A_i, B_i = B_i, A_i
    friends.append((A_i, B_i))

friends = list(set(friends))

friends_count = []

for friend_set in friends:
    friends_count.append(friend_set[0])
    friends_count.append(friend_set[1])
    
print(Counter(friends_count).most_common()[0][1]+1)

Submission status: Wrong Answer

Solution code:
(n,m),*e=[[*map(int,i.split())]for i in open(0)]
d=[[]for i in range(n+1)]
dd=[[]for i in range(n+1)]
for i,j in e:
    d[i]+=[j]
    d[j]+=[i]
for i in range(n+1):
    for j in set(d[i]):
        dd[i]+=d[j]
print(max(len(set(dd[i]))for i in range(n+1)))

Submission status: Wrong Answer

Solution code:
import collections as cl
N, M = map(int, input().split())
g = [[i + 1] for i in range(N)]
ans = 0
for _ in range(M):
    a, b = map(int, input().split())
    g[a - 1].append(b)
    g[b - 1].append(a)

for i in range(N):
    c = cl.Counter(g[i])
    ans = max(ans, len(c))

print(ans)

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 = set()
    for i in range(M):
        args = input().split()

        isHit = False
        for group in groupList:
            hit0 = args[0] in group
            hit1 = args[1] in group

            if hit0 and (not hit1):
                groupList.remove(group)
                group += args[1]
                groupList.add(group)
            if (not hit0) and (hit1):
                groupList.remove(group)
                group += args[0]
                groupList.add(group)

        if not isHit:
            groupList.add(str(args[0]) + str(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:
import copy

n,m = map(int,input().split())
f = []

for i in range(m):
    a,b=map(int,input().split())
    flg = True
    for j in f:
        if a in j:
            j.add(b)
            flg = False
        elif b in j:
            j.add(a)
            flg = False

    if flg:
        f.append({a,b})

nf = copy.deepcopy(f)

for i in f:
    for j in i:
        for k in f:
            if j in k:
                nf.append(i|k)

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


print(ans)

Submission status: Wrong Answer

Solution code:
import os

n,m = (int(x) for x in input().split())
if m==0:
    print(1)
    exit()
friendlist = [0]*n
classes = 1
for i in range(m):
    a,b = (int(x)-1 for x in input().split())
    if friendlist[a]!=0:
        friendlist[b] = friendlist[a]
    elif friendlist[b]!=0:
        friendlist[a] = friendlist[b]
    else:
        friendlist[a] = classes
        friendlist[b] = classes
        classes += 1

count = [0]*classes
for i in range(n):
    count[friendlist[i]] += 1
print(max(count[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])

if m == 0:
    print(1)
    exit()

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

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

# print('uf {}'.format(uf.par))
# print(*m.items(),sep='\n')

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:
N, M = map(int,input().split())

edge_list = [set() for i in range (N)]


for i in range (M):
    A,B = map(int,input().split())
    edge_list[A-1].add(B-1)
    edge_list[B-1].add(A-1)


edge_list = list(map(len,edge_list))

print(max(edge_list)+1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n,m = MI()
graph = [{j} for j in range(n+1)]
for i in range(m):
    a,b = MI()
    graph[a].add(b)
    graph[b].add(a)
ans_li = []
visited = set()
for j in range(1,n+1):
  ans = set()
  if j not in visited:
    visited.add(j)
    ans = ans|graph[j]
    for k in graph[j]:
      visited.add(k)
      ans= ans|graph[k]
    ans_li.append(len(ans))
print(max(ans_li))

Submission status: Wrong Answer

Solution code:
def main():
    n, m = map(int, input().split())
    dic1 = dict() 
    if m == 0:
        print(1)
        exit()
    a, b = map(int, input().split())
    dic1[a] = 1
    dic1[b] = 1
    

    for _ in range(m-1):
        a, b = map(int, input().split())
        if a not in dic1 and b not in dic1:
            dic1[a] = max(dic1.values()) + 1
            dic1[b] = dic1[a]
        elif a in dic1 and b not in dic1:
            dic1[b] = dic1[a]
        elif a not in dic1 and b in dic1:
            dic1[a] = dic1[b]
    #print(dic1)
    flipped = {}

    for key, value in dic1.items():
        if value not in flipped:
            flipped[value] = [key]
        else:
            flipped[value].append(key)
    ans = 0
    for key in flipped:
        tmp = len(flipped[key])
        if ans < tmp:
            ans = tmp
    print(ans)
        

    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

edges = defaultdict(set)
for _ in range(m):
  a, b = map(int, input().split())
  edges[a].add(b)
  edges[b].add(a)
  
for _ in range(m):
  for i in range(n):
    eee = edges[i]
    for e in eee:
      edges[i] = edges[i] | edges[e]

result = 0
for i in range(n):
  size = len(edges[i])
  if result < size:
    result = size
print(result)

Submission status: Wrong Answer

Solution code:
def main():
    n, m = map(int, input().split())
    groups = [None] * n
    groups_member = [None] * n
    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[num_groups] = 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]
            _tmp = 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 m is None:
            break
        if max_people < len(m):
            max_people = len(m)
    if max_people == 0:
        max_people = 1

    print(max_people)
    # print(groups)
    # print(groups_member)


if __name__ == "__main__":
    main()