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:
# [] = list(map(int, input().split()))

[n, m] = list(map(int, input().split()))
abList = []
for i in range(m):
    addedList = list(map(int, input().split()))
    for j in range(2):
        addedList[j] -= 1
    abList.append(addedList)


class DisjointSet(object):

    def __init__(self):
        self.leader = {}  # maps a member to the group's leader
        self.group = {}  # maps a group leader to the group (which is a set)

    def add(self, a, b):
        leadera = self.leader.get(a)
        leaderb = self.leader.get(b)
        if leadera is not None:
            if leaderb is not None:
                if leadera == leaderb: return  # nothing to do
                groupa = self.group[leadera]
                groupb = self.group[leaderb]
                if len(groupa) < len(groupb):
                    a, leadera, groupa, b, leaderb, groupb = b, leaderb, groupb, a, leadera, groupa
                groupa |= groupb
                del self.group[leaderb]
                for k in groupb:
                    self.leader[k] = leadera
            else:
                self.group[leadera].add(b)
                self.leader[b] = leadera
        else:
            if leaderb is not None:
                self.group[leaderb].add(a)
                self.leader[a] = leaderb
            else:
                self.leader[a] = self.leader[b] = a
                self.group[a] = set([a, b])


ds = DisjointSet()
for i in abList:
    x, y = i[0], i[1]
    ds.add(x, y)
maxL = 0
for i,j in ds.group.items():
    if len(j) > maxL:
        maxL = len(j)
print(maxL)

Submission status: Wrong Answer

Solution code:
import math
import queue

n, m = map(int, input().split(" "))
abL = [list(map(int, input().split(" "))) for _ in range(m)]
visited = [False for _ in range(n + 1)]

d = {}

for a, b in abL:
    if a in d:
        d[a].add(b)
    else:
        d[a] = set([b])

    if b in d:
        d[b].add(a)
    else:
        d[b] = set([a])

ans = -1
for k, v in d.items():
    if not visited[k]:
        cnt = 0
        q = queue.Queue()
        q.put(k)
        while q.qsize() != 0:
            ss = q.get()
            cnt += 1
            if cnt >= n:
                break
            visited[ss] = True
            for dd in list(d[ss]):
                if not visited[dd]:
                    q.put(dd)
        ans = max(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    from collections import defaultdict
    n, m, *ab, = map(int, open(0).read().split())
    f = defaultdict(lambda: set())
    for i, j in zip(ab[::2], ab[1::2]):
        f[i].add(j)
        f[j].add(i)

    group = []
    i = 1
    g = {i}
    nx = {i}
    checked = set()
    ans = 0
    while i <= n:
        if i in checked:
            i += 1
            continue
        
        tmp = set()
        for j in list(nx):
            tmp |= f[j]
        tmp -= nx

        if len(tmp) == 0:
            checked |= g
            group.append(g)
            l = len(g)
            r = n - len(checked)
            ans = max(ans, l)
            if l >= r:
                break
            i += 1
            g = {i}
            continue
        else:
            g |= tmp
            nx = tmp

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

n, m = map(int, input().split())
if m == 0:
    print(1)
    exit()
if m == 1:
    print(2)
    exit()
ids = {i: 0 for i in range(1, n+1)}
id = 1
for _ in range(m):
    a, b = map(int, input().split())
    if ids[a] == 0 and ids[b] != 0:
        ids[a] = ids[b]
    elif ids[a] != 0 and ids[b] == 0:
        ids[b] = ids[a]
    elif ids[a] == 0 and ids[b] == 0:
        ids[a] = id
        ids[b] = id
        id += 1
print(max(collections.Counter(ids.values()).values()))

Submission status: Wrong Answer

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, Q = NMI()
    PAB = [NLI() for _ in range(Q)]
    

    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] = min(parent_x,parent_y)
        parents[y] = min(parent_x,parent_y)
 
 
        
    for q in range(Q):
        a = PAB[q][0]
        b = PAB[q][1]
        
        if a > b:
            a,b = b,a
        
        unite_children(a,b)

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

 
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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(set(map(tuple,F)))
  team = [0] * N
  for t in L:
    team[t[0]-1] += 1
    team[t[1]-1] += 1

  print(max(team)+1)

Submission status: Wrong Answer

Solution code:
def search(x, num):
#     nodes.remove(x)
#     for y in edge[x]:
#         edge[y].discard(x)
#     for y in list(edge[x]):
#         print(x,y)
#         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: Wrong Answer

Solution code:
import collections
N,M = map(int,input().split())
lsa = [0 for i in range(N+1)]
ii = 1
for i in range(M):
    a,b = map(int,input().split())
    if lsa[a] == 0 and lsa[b] == 0:
        lsa[a] = ii
        lsa[b] = ii
        ii += 1
    elif lsa[a] != 0 and lsa[b] == 0:
        lsa[b] = lsa[a]
    elif lsa[a] == 0 and lsa[b] != 0:
        lsa[a] = lsa[b]
counterA = collections.Counter(lsa)
counterA[0] = 1
print(max(counterA.values()))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
if m == 0:
    ans = 1
else:
  a = []
  b = []
  for i in range(m):
    aa, bb = input().split()
    a.append(aa)
    b.append(bb)
  f1 = []
  f1.append(a[0])
  for i in range(m):
    if a[i] in f1:
        if not(b[i] in f1):
          f1.append(b[i])
    elif b[i] in f1:
        if not(a[i] in f1):
          f1.append(a[i])
  ans = len(f1)
  j = 1
  rm = m - ans
  while (j < m) and (ans < rm):
    f2 = []
    if a[j] in f1 or b[j] in f1:
        j += 1
        continue
    if j < m:
      f2.append(a[j])
      f1.append(a[j])
      for k in range(j, m):
        if a[k] in f2:
          f2.append(b[k])
          f1.append(b[k])
        elif b[k] in f2:
          f2.append(a[k])
          f1.append(a[k])
      rans = len(f2)
      rm -= rans
      if rans > ans:
        ans = rans
    j += 1
print (ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
if M == 0:
  print(N)
else:
  F = list((sorted(map(int,input().split()))) for i in range(M))
  L = list(set(map(tuple,F)))
  team = [0] * N
  for t in L:
    team[t[0]-1] += 1
    team[t[1]-1] += 1

  print(max(team)+1)

Submission status: Wrong Answer

Solution code:
a,b = list(map(int, input().split()))
friend_li = [[] for _ in range(a)]

result = 0

for i in range(b):
  c,d = list(map(int, input().split()))
  friend_li[min(c-1,d-1)].append(max(c-1,d-1))

array = []
for i in range(len(friend_li)-1,-1,-1):
  friend_li[i] = list(set(friend_li[i]))
  for num in friend_li[i]:
    array += friend_li[num]
  friend_li[i] += array
  array = []

for element in friend_li:
  len_ = len(list(set(element)))
  if len_ > result:
    result = len_
print(result+1)

Submission status: Wrong Answer

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

group = [[] for i in range(n)]
group_num = [-1 for i in range(n+1)]
group_count = -1

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

len_max = -1
for i in range(len(group)):
    len_max = max(len_max, len(set(group[i])))

print(len_max)

Submission status: Wrong Answer

Solution code:

import sys
sys.setrecursionlimit(10**6)

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

lis = [[] for _ in range(N+1)]
for i in range(M):
    A,B = map(int,input().split())
    A,B = min(A,B),max(A,B)
    lis[A].append(B)
    
cnt = 0
seen = [False]*(N+1)
def dfs(v,graph):
    global cnt
    seen[v] = True
    for next_v in graph[v]:
        if seen[next_v] == True:
             continue
        if seen[next_v] == []:
             continue
        cnt += 1
        dfs(next_v,graph)
    return cnt

ma = 0
for j in range(N):
    cnt = 0
    if seen[j] == True:
        continue
    ma = max(ma,dfs(j,lis))
print(ma+1)

Submission status: Wrong Answer

Solution code:
from sys import stdin

# from pprint import pprint
# import math
# import collections

# n = stdin.readline().rstrip()
# n = int(n)

n, m = [int(x) for x in stdin.readline().rstrip().split()]
# a = [int(x) for x in l]

d = [stdin.readline().rstrip().split() for _ in range(m)]
d = [tuple(map(int, x)) for x in d]

# most friends
p = [0] * n
p_rel = {k: [] for k in range(n)}
for rel in d:
    p[rel[0] - 1] += 1
    p[rel[1] - 1] += 1

    p_rel[rel[0] - 1] += rel
    p_rel[rel[1] - 1] += rel

max_friends = max(p)

max_friends_idx = p.index(max_friends)

# print(p.index(max_friends))

x = set(p_rel[max_friends_idx])

ans = len(x)


print(ans)

Submission status: Wrong Answer

Solution code:

import sys
sys.setrecursionlimit(10**6)

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

lis = [[] for _ in range(N+1)]
for i in range(M):
    A,B = map(int,input().split())
    A,B = min(A,B),max(A,B)
    lis[A].append(B)
print(lis)
    
cnt = 0
seen = [False]*(N+1)
def dfs(v,graph):
    global cnt
    seen[v] = True
    for next_v in graph[v]:
        if seen[next_v] == True:
             continue
        if seen[next_v] == []:
             continue
        cnt += 1
        dfs(next_v,graph)
    return cnt

ma = 0
for j in range(N):
    cnt = 0
    if seen[j] == True:
        continue
    ma = max(ma,dfs(j,lis))
print(ma+1)

Submission status: Wrong Answer

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

team = [0] * N
for t in L:
  team[t[0]-1] += 1
  team[t[1]-1] += 1

print(max(team)+1)

Submission status: Wrong Answer

Solution code:

n, m = map(int, input().split())
g = []
ma = 2
for i in range(0, m, 1):
    a, b = map(int, input().split())
    if len(g) == 0:
        g.append([a, b])
        continue
    for j in g:
        if a in j or b in j:
            j.extend([a, b])
            j = set(j)
            ma = max(len(j), ma)
    g.append([a, b])
print(ma)

Submission status: Wrong Answer

Solution code:
import numpy as np

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


par = [i for i in range(N+1)]
size = [1 for _ in range(N+1)]

def find(x):
    if par[x] == x:
        return x
    else:
#        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x] = y
    size[y] = size[x] + size[y]
    size[x] = 0

for AB in ABs:
    unite(AB[0],AB[1])

print(max(size))

Submission status: Wrong Answer

Solution code:

n, m = map(int, input().split())
g = []
ma = 0
for i in range(0, m, 1):
    a, b = map(int, input().split())
    if len(g) == 0:
        g.append([a, b])
        continue
    for j in g:
        if a in j or b in j:
            j.extend([a, b])
            j = set(j)
            ma = max(len(j), ma)
    g.append([a, b])
print(ma)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n, m = map(int, input().split())
    flist = [[]]
    for _ in range(m):
        a, b = map(int, input().split())
        for fg in flist:
            if a in fg:
                fg.append(b)
            if b in fg:
                fg.append(a)
            else:
                flist.append([a,b])
    for fg in flist:
        c = set(fg)
        ans = max(ans, len(c))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M,*A=map(int,open(0).read().split())
d={}
for i in range(0,len(A),2):
    a=A[i]
    b=A[i+1]
    if a in d:
        if b in d:
            d[a]=d[b]=d[a]|d[b]
        else:
            d[a].add(b)
            d[b]=d[a]
    elif b in d:
        d[b].add(a)
        d[a]=d[b]
    else:
        s=set([a,b])
        d[a]=d[b]=s
print(max([1]+[len(v) for v in d.values()]))

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    pairs = []
    for i in range(M):
        pairs.append(input().split())

    groups=[]

    for pair in pairs:
        blnExists = False
        for group in groups:
            if (pair[0] in group or pair[1] in group) == True:
                if (pair[0] in group) == False:
                    group.append(pair[0])
                if (pair[1] in group) == False:
                    group.append(pair[1])
                blnExists = True
        if blnExists == False:
            groups.append(pair)

    max_len = 0
    max_group_index =-1
    for i in range(len(groups)):
        if len(groups[i]) > max_len :
            max_len = len(groups[i])
            max_group_index = i

    print(max_len)
main()

Submission status: Wrong Answer

Solution code:
import copy
N,M = map(int, input().split())
path = [-1] * N
for m in range(M):
  A,B = map(lambda x: int(x) - 1, input().split())
  if path[A] > path[B]:
    tmp = copy.deepcopy(A)
    A = copy.deepcopy(B)
    B = copy.deepcopy(tmp)
  Aroot = copy.deepcopy(A)
  Broot = copy.deepcopy(B)
  while -path[Aroot] < 0:
    Aroot = path[Aroot]
  while -path[Broot] < 0:
    Broot = path[Broot]
  path[Aroot] += copy.deepcopy(path[Broot])
  tmp = copy.deepcopy(A)
  path[B] = copy.deepcopy(tmp)
print(max([-m for m in path]))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
F = list((tuple(map(int,input().split()))) for i in range(M))
L = list(set(F))
team = [0] * N
for t in L:
  team[t[0]-1] += 1
  team[t[1]-1] += 1
print(max(team)+1)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n, m = map(int, input().split())
    flist = [[]]
    for _ in range(m):
        a, b = map(int, input().split())
        for fg in flist:
            if a in fg:
                fg.append(b)
            elif b in fg:
                fg.append(a)
            else:
                flist.append([a,b])
    for fg in flist:
        c = set(fg)
        ans = max(ans, len(c))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

groups = [1e10 for i in range(N)]
new_group = 0
for _ in range(M):
    i, j = map(int, input().split())
    i-=1
    j-=1
    if groups[i]==1e10 and groups[j]==1e10:
        groups[i] = new_group
        groups[j] = new_group
        new_group+=1
    elif groups[i]==1e10:
        group = groups[j]
        groups[i]=group
    else:
        group = groups[i]
        groups[j]=group

group_nums = [0 for _ in range(new_group)]
for g in groups:
    if g!=1e10:
        group_nums[g]+=1

if new_group==0:
    print(N)
else:
    print(max(group_nums))

Submission status: Wrong Answer

Solution code:
####################################################################
import sys
def _p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
def _pa(_aa):
  #return
  for _a in _aa: _p(_a)
####################################################################

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

F=[ [] for i in range(N+1) ]
for i in range(M):
  a,b = map(int, input().split())
  F[a].append(b)
  F[b].append(a)

# _pa(F)

from collections import deque

G=[-1]*(N+1)
for i in range(N+1):
  if G[i]>-1: continue
  G[i] = i
  Q = deque()
  Q.append(F[i])
  while Q:
    l = Q.popleft()
    for f in l:
      if G[f]==-1:
        G[f] = i
        Q.append([f])

# _pa(G)


from collections import Counter
C = Counter(G)
ans = 0
for k,v in C.items():
  ans = max(ans, v)

print(ans)

Submission status: Wrong Answer

Solution code:
a,b = list(map(int, input().split()))
friend_li = [[] for _ in range(a)]

result = 0

for i in range(b):
  c,d = list(map(int, input().split()))
  friend_li[min(c-1,d-1)].append(max(c-1,d-1))

for i in range(len(friend_li)-1,-1,-1):
  for num in friend_li[i]:
    friend_li[i] += friend_li[num]

for element in friend_li:
  len_ = len(list(set(element)))
  if len_ > result:
    result = len_
print(result+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
fr = [set() for x in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    fr[a].add(b)
    fr[b].add(a)
max_fr = 0
for i in fr:
    max_fr = max(len(i)+1, max_fr)
print(max_fr)

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import connected_components

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

if m != 0:
    edge = np.array([input().split() for _ in range(m)], dtype = np.int64).T
    tmp = np.ones(m, dtype = np.int64).T
    graph = csr_matrix((tmp, (edge[:] -1)), (n, n))

    cnt = collections.Counter(connected_components(graph)[1])

    print(max(cnt.values()))
else:
    print('0')

Submission status: Wrong Answer

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

for i in range(M):
    A,B = list(map(int, input().split()))
    if (team_table[A-1] == 0)&(team_table[B-1] == 0):
        color = A
        team_table[A-1] = color 
        team_table[B-1] = color
    elif (team_table[A-1] == 0)&(team_table[B-1] != 0):
        team_table[A-1] = team_table[B-1]
    elif (team_table[A-1] != 0)&(team_table[B-1] == 0):
        team_table[B-1] = team_table[A-1]

if M != 0:
    cns = -1
    for i in range(N):
        if team_table[i] == 0:
            team_table[i] = cns
            cns = cns - 1

    ans = collections.Counter(team_table).most_common()[0][1]
else:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
####################################################################
import sys
def _p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
def _pa(_aa):
  #return
  for _a in _aa: _p(_a)
####################################################################

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

F=[ [] for i in range(N+1) ]
for i in range(M):
  a,b = map(int, input().split())
  F[a].append(b)
  F[b].append(a)

# _pa(F)

from collections import deque

G=[-1]*(N+1)
for i in range(N+1):
  if G[i]>0: continue
  G[i] = i
  Q = deque()
  Q.append(F[i])
  while Q:
    l = Q.popleft()
    for f in l:
      if G[f]==-1:
        G[f] = i
        Q.append([f])

# _pa(G)


from collections import Counter
C = Counter(G)
ans = 0
for k,v in C.items():
  ans = max(ans, v)

print(ans)

Submission status: Wrong Answer

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

l = [[] for i in range(N)]
for _ in range(M):
    AB = list(map(int,input().split()))
    if AB[0] < AB[1]:
        A = AB[0]
        B = AB[1]
    else:
        A = AB[1]
        B = AB[0]
    if B-1 not in l[A-1]:
        l[A-1].append(B-1)

ma = 0
for i in l:
    if len(i) != 0:
        ma = max(ma,len(i))
print(ma + 1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
fr = [set() for x in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    fr[a].add(b)
    fr[b].add(a)
print(fr)
max_fr = 0
for i in fr:
    max_fr = max(len(i)+1, max_fr)
print(max_fr)

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-1, b-1)
# 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 = max(m.values())
print(ans)

Submission status: Wrong Answer

Solution code:
n,m= map(int, input().split())
par = [i for i in range(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:
    par[x] = y
    find(x)
  else:
    par[y] = x
    find(y)

if m > 0:  
  for i in range(m):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)
  
  ans = [0] * n
  Max = 0
  #for i in range(n):
  #  find(i)
  for i in par:
    ans[i] += 1
  for i in ans:
    if i > Max:
      Max = i
  
  print(Max)
else:
  print(1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
fr = [[] for x in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    if b not in fr[a]:
        fr[a].append(b)
        fr[b].append(a)
max_fr = 0
for i in fr:
    max_fr = max(len(i)+1, max_fr)
print(max_fr)

Submission status: Wrong Answer

Solution code:
def search(x, 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:
        nodes.remove(x)
        tmp = search(x, 0)
        ans = max(tmp, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
A = []*m
B = []*m
for i in range(m):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
S = [set([i+1]) for i in range(n)]
#print(S)
for i in range(m):
    S[A[i]-1] = S[A[i]-1].union(S[B[i]-1])
    S[B[i]-1] = S[B[i]-1].union(S[A[i]-1])
    #print(S)

ans = 1
for i in range(n):
    ans = max(ans, len(S[i]))

print(str(ans))

Submission status: Wrong Answer

Solution code:
a,b = list(map(int, input().split()))
friend_li = [[] for _ in range(a)]

result = 0

for i in range(b):
  c,d = list(map(int, input().split()))
  friend_li[min(c-1,d-1)].append(max(c-1,d-1))

for i in range(len(friend_li)-1,-1):
  for num in friend_li[i]:
    friend_li[i].append(friend_li[num])

for element in friend_li:
  len_ = len(list(set(element)))
  if len_ > result:
    result = len_
print(result+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
A = []*m
B = []*m
for i in range(m):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
S = [set([i+1]) for i in range(n)]
#print(S)
for i in range(m):
    S[A[i]-1] = S[A[i]-1].union(S[B[i]-1])
    S[B[i]-1] = S[B[i]-1].union(S[A[i]-1])
    print(S)

ans = 1
for i in range(n):
    ans = max(ans, len(S[i]))

print(str(ans))

Submission status: Wrong Answer

Solution code:
def search(x, num):
    for y in list(edge[x]):
        if y in nodes:
            nodes.remove(y)
            edge[y].discard(x)
            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])

Submission status: Wrong Answer

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

q = [0]*(n+1)

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)

dist = [-1] * (n+1)
dist[0] = 0
dist[1] = 0

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

d = deque()
a = 0
for l,j in enumerate(q):
    b = set()
    if j == 0:
        d.append(l)
        while d:
            v = d.popleft()
            b.add(v)
            q[v] = -1

            for i in graph[v]:
                b.add(i)
                q[i] = -1

                if dist[i] != -1:
                    continue
                dist[i] = dist[v] + 1
                d.append(i)
        a = max(a,len(b))
print(a)

Submission status: Wrong Answer

Solution code:
a,b = list(map(int, input().split()))
friend_li = [[] for _ in range(a)]

result = 0

for i in range(b):
  c,d = list(map(int, input().split()))
  friend_li[c-1].append(d-1)
  friend_li[d-1].append(c-1)

for i in range(len(friend_li)-1,-1):
  for num in friend_li[i]:
    friend_li[i].append(friend_li[num])

for element in friend_li:
  len_ = len(list(set(element)))
  if len_ > result:
    result = len_
print(result+1)

Submission status: Wrong Answer

Solution code:
a,b = list(map(int, input().split()))
friend_li = [[] for _ in range(a)]

result = 0

for i in range(b):
  c,d = list(map(int, input().split()))
  friend_li[c-1].append(d-1)
  friend_li[d-1].append(c-1)

for i in range(len(friend_li)-1,-1):
  for num in friend_li[i]:
    friend_li[i].append(friend[num])

for element in friend_li:
  len_ = len(list(set(element)))
  if len_ > result:
    result = len_
print(result+1)

Submission status: Wrong Answer

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

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

a, b = list(map(int, input().split()))
s = set()
s.add(a)
s.add(b)
sets.append(s)
for i in range(1, m):
    a, b = list(map(int, input().split()))
    f = True
    for si in range(len(sets)):
        if a in sets[si] or b in sets[si]:
            sets[si].add(a)
            sets[si].add(b)
            f = False
            break
    if f:
        s = set()
        s.add(a)
        s.add(b)
        sets.append(s)

ans = 0
for s in sets:
    ans = max(len(s), ans)
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])

    groupTable = [i for i in range(N + 1)]

    for i in range(M):
        args = list(map(lambda x: int(x), input().split()))
        if groupTable[args[0]] > groupTable[args[1]]:
            groupTable[args[0]] = groupTable[args[1]]
        else:
            groupTable[args[1]] = groupTable[args[0]]

    maxNum = 0
    for i in set(groupTable):
        counter = groupTable.count(i)
        maxNum = max(maxNum, counter)

    print(maxNum)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N,M,*A=map(int,open(0).read().split())
d={}
ss=[]
for i in range(0,M*2,2):
    a=A[i]
    b=A[i+1]
    if a in d:
        if b in d:
            d[a]|=d[b]
            d[b]=d[a]
        else:
            d[a].add(b)
            d[b]=d[a]
    elif b in d:
        d[b].add(a)
        d[a]=d[b]
    else:
        s=set([a,b])
        ss.append(s)
        d[a]=d[b]=s
print(max([1]+[len(s) for s in ss]))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
friends_set_list = [set([i]) for i in range(N+1)]
ans = 1
for i in range(M):
    A, B = map(int, input().split())
    friends_set_list[B].add(A)
    friends_set_list[A] |= friends_set_list[B]
    friends_set_list[B] = friends_set_list[A]
    num = len(friends_set_list[A])
    if ans < num:
        ans = num

print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
if m == 0:
  print(1)
elif m == 1:
  print(2)
else:
  ls = []
  for i in range(n):
    ls.append(set([i+1]))
  for i in range(m):
    a,b = map(int, input().split())
    ls[a-1].add(b)
    ls[b-1].add(a)
  
  ans = 0
  for s in ls:
    ans = max(ans, len(s))
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M = [int(x) for x in input().split()]

friends_map = {}

for m in range(M):
    a, b = [int(x) - 1 for x in input().split()]

    if a in friends_map:
        friends_map[a].add(b)
    else:
        friends_map[a] = {b}

    if b in friends_map:
        friends_map[b].add(a)
    else:
        friends_map[b] = {a}

stack = deque()
stack.appendleft((0, 1))

remain_user = {i for i in range(N)}

max_group = 0
while stack:
    now, group = stack.popleft()
    remain_user.discard(now)

    if now in friends_map:
        for next_node in friends_map[now]:
            if next_node in remain_user:
                group += 1
                stack.appendleft((next_node, group))
                remain_user.discard(next_node)

    if group > max_group:
        max_group = group

    if not stack:
        if remain_user:
            stack.appendleft((remain_user.pop(), 1))

print(max_group)