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

input_groups =[]
groups = [i for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    a = a-1
    b = b-1
    if a > b:
        a, b = b, a
    input_groups.append((a,b))
for a, b in sorted(input_groups):
    groups[b] = groups[a]

group_count = Counter(groups)

max_num= 0
for group, num in group_count.items():
    if max_num < num:
        max_num = num

print(max_num)

Submission status: Wrong Answer

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

def main():
    n, m = map(int, input().split())
    ab_arr = []
    for _ in range(m):
        ab = list(map(int, input().split()))
        ab.sort()
        ab_arr.append(ab)

    ab_arr.sort(key=lambda ab: (ab[0], ab[1]))
    # print(ab_arr)
    parent = [i for i in range(n+1)]
    cnt = [0 for _ in range(n+1)]

    for ab in ab_arr:
        a, b = ab
        if parent[a] < parent[b]:
            parent[b] = parent[a]
        else:
            parent[a] = parent[b]

    for ab in ab_arr:
        a, b = ab
        if parent[a] < parent[b]:
            parent[b] = parent[a]
        else:
            parent[a] = parent[b]
    # print(parent)

    for p in parent:
        cnt[p] += 1

    print(max(cnt))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
mInfos = [list(map(int, input().split())) for _ in range(M)]
gl = [0]*N
mc = [0]*N
gc = 0
guru = []
for i in range(M):
    mInfo = mInfos[i]
    p1 = mInfo[0]
    p2 = mInfo[1]
    naiflag = True
    if gl[p1-1] == 0 and gl[p2-1] == 0:
        gl[p1 - 1] = gc + 1
        gl[p2 - 1] = gc + 1
        mc[gc] = 2
        gc += 1
    elif gl[p1-1] != 0:
        gl[p2 - 1] = gl[p1-1]
        mc[p1-1] += 1
    elif gl[p2-1] != 0:
        gl[p1 - 1] = gl[p2 - 1]
        mc[p2 - 1] += 1
    else:
        gl = [gl[p1-1] if j == gl[p2-1] else j for j in gl]
        mc[p2 - 1] = 0
        gc -= 1
mi = 0
for i in range(1,gc+1):
    dd = gl.count(i)
    mi = max(mi,dd)
print(mi)

Submission status: Wrong Answer

Solution code:
import numpy as np
from copy import deepcopy
from heapq import heappop, heappush
from bisect import bisect_left, bisect
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations

N, M = map(int, input().split())
A = [0] * M
B = [0] * M
for i in range(M):
    A[i], B[i] = map(int, input().split())

R = {i: set() for i in range(N)}

for i in range(M):
    R[A[i]-1].update([B[i]-1])

for i in range(N):
    for j in range(i + 1, N):
        # print(i, j, R[i], R[j])
        if len(R[i] & R[j]) > 0:
            R[i].update(R[j])
            R[j].clear()

s = 0
for i in range(N):
    # print(R[i])
    if (len(R[i]) > 0):
        s += len(R[i])

print(s)
exit()

Submission status: Wrong Answer

Solution code:
pairs=[]

n,m=list(map(int,input().split()))
d=[set() for i in range(n+1)]
for x in range(m):
    p=sorted(list(map(int,input().split())))
    if p not in pairs:
        d[p[0]].add(p[0])
        d[p[0]].add(p[1])
       
        d[p[0]]=d[p[0]].union(d[p[1]])
        d[p[1]]=set()
        pairs.append(p)
l=0
for i in d:
    a=len(i)
    if l<a:
        l=a
print(l)

Submission status: Wrong Answer

Solution code:
from collections import Counter


class UnionFind:
    def __init__(self, n):
        super().__init__()
        self.par = [i for i in range(n)]
        self.rank = [0 for i in range(n)]

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

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[x] = y
            elif self.rank[x] > self.rank[y]:
                self.par[y] = x
            else:
                self.par[x] = y
                self.rank[y] += 1


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

# print(Counter(union.par).values())
print(max(Counter(union.par).values()))

Submission status: Wrong Answer

Solution code:
from collections import Counter

class UnionFind:
    def __init__(self, n):
        self.par = list(range(n)) #親
        self.rank = [0] * n #根の深さ

    # xの属する根を求める
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            # if they have the same parent, no need to union
            return
        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

    # xとyが同じ集合に属するかを判定（同じ根に属するか）
    def same(self, x, y):
        return self.find(x) == self.find(y)


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

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

c = Counter(uf.par)

print(max(c.values()))

Submission status: Wrong Answer

Solution code:
import collections
def solve():
  N,M = map(int,input().split())
  ABlist = [[0 for _ in range(2)] for _ in range(M)]
  WA = [0]*N
  WAD = []
  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(key=lambda x: (x[0],x[1]))
  for i in range(M):
    A = ABlist[i][0]
    B = ABlist[i][1]
    if WA[B-1]<WA[A-1]:
      WAD.append([WA[B-1],WA[A-1]])
    else:
      WA[B-1] = WA[A-1]
  c = collections.Counter(WA)
  if len(WAD)>0:
    WAD.sort(key=lambda x: (x[0],x[1]),reverse=True)
    for i in range(len(WAD)):
      c[WAD[i][0]] += c[WAD[i][1]]
  print(c.most_common()[0][1])
solve()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N,M= (int(x) for x in input().rstrip('\n').split())
f = {x:set([x]) for x in range(1,N+1)}
for _ in range(M):
  A,B = (int(x) for x in input().rstrip('\n').split())
  if f[A] != f[B]:
    f[A] |= f[B]
    f[B] |= f[A]
print(max(len(x) for x in f.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[y] = x


        
    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())
friendlist={i+1:0 for i in range(N)}
sumg=0
for m in range(M):
  A,B=map(int,input().split())
  if friendlist[A]==0 and friendlist[B]==0:
    sumg+=1
    friendlist[A]=sumg
    friendlist[B]=sumg
  elif friendlist[A]==0:
    friendlist[A]=friendlist[B]
  elif friendlist[B]==0:
    friendlist[B]=friendlist[A]
  elif friendlist[A]!=friendlist[B]:
    k=friendlist[B]
    for i in range(1,N+1):
      if friendlist[i]==k:
        friendlist[i]=friendlist[A]
maxlist=[0 for _ in range(sumg+1)]
for i in range(1,N+1):
  maxlist[friendlist[i]]+=1
print(max(maxlist))

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

input_groups =[]
groups = [i for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    input_groups.append((a,b))
for a, b in sorted(input_groups):
    a = a-1
    b = b-1
    if a > b:
        a, b = b, a
    groups[b] = groups[a]

group_count = Counter(groups)

max_num= 0
for group, num in group_count.items():
    if max_num < num:
        max_num = num

print(max_num)

Submission status: Wrong Answer

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

friends = []
for _ in range(n):
    friends.append(set([]))

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    friends[a].add(b)
    friends[b].add(a)
    for aElement in friends[a]:
        friends[aElement].add(b)
        friends[b].add(aElement)
    for bElement in friends[b]:
        friends[bElement].add(a)
        friends[a].add(bElement)

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

Submission status: Wrong Answer

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

def main():
    n, m = map(int, input().split())
    ab_arr = []
    for _ in range(m):
        ab = list(map(int, input().split()))
        ab.sort()
        ab_arr.append(ab)

    # ab_arr.sort(key=lambda ab: (ab[0], ab[1]))
    # print(ab_arr)
    parent = [i for i in range(n+1)]
    cnt = [0 for _ in range(n+1)]

    for ab in ab_arr:
        a, b = ab
        if parent[a] < parent[b]:
            parent[b] = parent[a]
        else:
            parent[a] = parent[b]

    for ab in ab_arr:
        a, b = ab
        if parent[a] < parent[b]:
            parent[b] = parent[a]
        else:
            parent[a] = parent[b]
    # print(parent)

    for p in parent:
        cnt[p] += 1

    print(max(cnt))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
n,m = map(int,input().split())
a = get_unique_list([list(map(int,input().split())) for _ in range(m)])

import networkx as nx
G = nx.Graph()
G.add_edges_from(a)
nx.connected_components(G)

max_size = 0

for component in nx.connected_components(G):
    if len(component) > max_size:
        max_cluster = component
        max_size = len(max_cluster)
print(max_size)

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) for x in input().split())
    if friendlist[a-1]!=0:
        friendlist[b-1] = friendlist[a-1]
    elif friendlist[b-1]!=0:
        friendlist[a-1] = friendlist[b-1]
    else:
        friendlist[a-1] = classes
        friendlist[b-1] = classes
        classes += 1

count = [0]*classes
for i in friendlist:
    count[i] += 1
print(max(count[1:]))

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)]
call_check = [0] * (N + 1)

for a, b in A_B:
    if call_check[a] == 0 or call_check[b] == 0:
        call_check[a] = 1
        call_check[b] = 1
        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

if M == 0:
    ans = 1
else:
    ans = 0
    for friend in friend_list:
        len_friend = len(friend)
        ans = max(ans, len_friend)
print(ans)

Submission status: Wrong Answer

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

for i in range(M):
  a, b = input().split()
  if a > b: a, b = b, a
  r.append((a, b))

R = list(set(r))
M = len(R)
c = []

for i in range(M):
  for j in range(len(c)):
    if R[i][0] and R[i][1] in c[j]: break
    if R[i][0] in c[j] and not R[i][1] in c[j]:
      c[j].append(R[i][1])
      break
    if not R[i][0] in c[j] and R[i][1] in c[j]:
      c[j].append(R[i][0])
      break
  else: c.append([R[i][0], R[i][1]])

ans = 0
for i in range(len(c)):
  ans = max(ans, len(c[i]))

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):
    temp = set(map(int, input().split()))
    if temp & all_set:
        for j in range(len(friends)):
            if temp & friends[j]:
                friends[j] |= temp
                if len(friends[j]) > ans:
                    ans = len(friends[j])
                break
    else:
        friends.append(temp)
    all_set |= temp

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N, M = map(int, input().split())
D = dict([(i,i) for i in range(1,N+1)])

L = []

for i in range(M):
    A, B = map(int, input().split())
    if A > B:
        A,B = B,A
    L += [(A,B)]
    
L = set(L)

for i in L:
    A,B = i
    m = min([D[A], D[B], A, B])
    D[A] = m
    D[B] = m
    
D = collections.Counter(D.values())
print(max(D.values()))

Submission status: Wrong Answer

Solution code:



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

AB = []
for i in range(M):
    AB.append(list(map(int,input().split())))

fri = [[] for i in range(N+1)]
for i in range(M):
    fri[AB[i][0]].append(AB[i][1])
    fri[AB[i][1]].append(AB[i][0])

for i in range(1,N+1):
    fri[i] = list(set(fri[i]))
# print('fri:',fri)

'''
from collections import deque
que = deque([])
que.append((fri[1]))
while que:
    p = que.popleft()
    print(p)
    for i in range(p):
        fri[p].append()
'''

for i in range(1,N+1):
    for j in range(len(fri[i])):
        p = fri[fri[i][j]]
        # print('p:',p)
        for k in range(len(p)):
            if p[k] != i:
                fri[i].append(p[k])

for i in range(1,N+1):
    fri[i] = list(set(fri[i]))
# print('fri:',fri)

out=[]
for i in range(1,N+1):
    out.append(len(fri[i]))
print(max(out)+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
s = []
for i in range(m):
    a, b = map(int, input().split())
    for j in s:
        if a in j:
            if b in j: break
            else:
                j.append(b)
                break
        elif b in j:
            j.append(a)
            break
    else:
        s.append([a, b])
m = 0
for k in s:
    m = max(m, len(k))
print(m)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    parent = [-1] * (N+1)
    rank = [0] * (N+1)
    
    def find(x):
        if parent[x]<0:
            return x
        else:
            parent[x] = find(parent[x])
            return parent[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

        if rank[x]>rank[y]:
            parent[x] += parent[y]
            parent[y] = x
        else:
            parent[y] += parent[x]
            parent[x] = y
            if rank[x]==rank[y]:
                rank[y] += 1

    for i in range(M):
        unite(A[i], B[i])

    parent = parent[1:]
    rank = rank[1:]

    heights = [0] * N
    for i in range(len(parent)):
        if parent[i]>0:
            heights[parent[i]-1] += 1

    #print(parent)
    #print(heights)
    print(max(heights)+1)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
T=[set([i]) for i in range(N+1)]
AB=[sorted(list(map(int,input().split()))) for _ in range(M)]

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
AB=get_unique_list(AB)
M=len(AB)
for i in range(M):
  a,b=AB[i]
  T[a].add(b)
  T[b].add(a)

unions=[]
for i in range(M):
  a,b=AB[i]
  unions.append(T[a].union(T[b]))

ans=0
for j in range(1,len(unions)):
  ans=max(ans,len(unions[j]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
import numpy as np
#n = int(input())
n, m = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

group = [0 for i in range(n)]
l = []
for i in range(m):
    a, b = map(int, sys.stdin.readline().split())
    if a < b:
        c = a
        d = b
    else:
        c = b
        d = a
    l.append([c, d])

l.sort(key=lambda x:(x[0], x[1]))
change = [i+1 for i in range(n)]
cur = 0
for i in range(m):
    e = l[i][0]
    f = l[i][1]
    if group[e-1] == 0 and group[f-1] == 0:
        group[e-1] = cur + 1
        group[f-1] = cur + 1
        cur += 1
    elif group[e-1] == 0 and group[f-1] != 0:
        group[e-1] = group[f-1]
    elif group[f-1] == 0 and group[e-1] != 0:
        group[f-1] = group[e-1]
    elif group[e-1] != group[f-1]:
        x = min(group[e-1], group[f-1])
        y = max(group[e-1], group[f-1])
        change[y-1] = change[x-1]

h = collections.Counter(group)
#print(h)

k = max(change)
#print(change)
p = [0 for i in range(k)]
for i in range(1, n):
    p[change[i-1]-1] += h[i]

#print(p)
print(max(p))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n, m = map(int, input().split())
L = []
for _ in range(m):
    a, b = map(int, input().split())
    if a > b:
        a, b = b, a
    L.append([a, b])
L.sort()

friends = [i for i in range(n + 1)]
for a, b in L:
    if friends[a] < friends[b]:
        friends[b] = friends[a]
    elif friends[a] > friends[b]:
        friends[a] = friends[b]
C = Counter(friends)
print(max(C.values()))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for l in range(m)]
max1 = 0
for i in range(m):
    for j in range(i + 1, m):
        if not set(a[i]).isdisjoint(set(a[j])):
            a[i].extend(a[j])
    a[i] = list(set(a[i]))
    max1 = max(max1, len(a[i]))
print(max1)

Submission status: Wrong Answer

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

for i in range(M):
    j, k = list(map(int, input().split()))
    for z  in range(len(A)):
        if j in A[z] and k in A[z]:
            break
        elif j in A[z] and k not in A[z]:
            A[z].append(k)
            break
        elif j not in A[z] and k in A[z]:
            A[z].append(j)
            break
        elif z == len(A)-1:
            A.append([j, k])

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

Submission status: Wrong Answer

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

for k in range(m):
    a, b = map(int, input().split())
    for i, group in enumerate(groups):
        if i == count:
            groups[i] += [a, b]
            count += 1
            break
        elif a in set(group) or b in set(group):
            groups[i] += [a, b]
            break
print(len(set(groups[0])))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)
n,m = map(int,input().split())
graph = [[] for _ in range(n+1)]
for _ in range(m):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
ans = 0
def dfs(node):
    todo = set()
    for nextnode in graph[node]:
        if tf[nextnode] == 0 :
            tf[nextnode] = 1
            seen.add(nextnode)
            todo.add(nextnode)
    for nextnode in todo:
        dfs(nextnode)
done = set()
for i in range(1,n+1):
    if i in done:
        continue
    else:
        done.add(i)
        tf = [0 for _ in range(n+1)]
        seen = set()
        dfs(i)
        ans = max(ans,sum(tf))
        done |= seen
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
group = [1]*N
for i in range(M):
    group[AB[i][0]-1] += 1
    group[AB[i][1]-1] += 1
print(max(group))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
sets = [{}]+[{i+1} for i in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  if b in sets[a]:
    pass
  else:
    sets[a] = sets[a] | sets[b]
    sets[b] = sets[a]
print(max(len(s) for s in sets))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
friendlist={i+1:0 for i in range(N)}
sumg=0
for m in range(M):
  A,B=map(int,input().split())
  if friendlist[A]==0 and friendlist[B]==0:
    sumg+=1
    friendlist[A]=sumg
    friendlist[B]=sumg
  elif friendlist[A]==0:
    friendlist[A]=friendlist[B]
  elif friendlist[B]==0:
    friendlist[B]=friendlist[A]
  elif friendlist[A]!=friendlist[B]:
    for i in range(1,N+1):
      k=friendlist[B]
      if friendlist[i]==k:
        friendlist[i]=friendlist[A]
maxlist=[0 for _ in range(sumg+1)]
for i in range(1,N+1):
  maxlist[friendlist[i]]+=1
print(max(maxlist))

Submission status: Wrong Answer

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

G = []
lookup_tab = {}

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

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

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
A = [[] for i in range(M)]
B = [[] for i in range(M)]
for i in range(M):
    A[i], B[i] = list(map(int, input().split()))

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

for i in range(M):
    if A[i] not in l[B[i] - 1]:
        l[B[i] - 1].append(A[i])
    if B[i] not in l[A[i] - 1]:
        l[A[i] - 1].append(B[i])

b = 0
ans = 0
for x in l:
    b = len(x)
    ans = max(b, 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) for x in input().split())
    if friendlist[a-1]!=0:
        friendlist[b-1] = friendlist[a-1]
    elif friendlist[b-1]!=0:
        friendlist[a-1] = friendlist[b-1]
    else:
        friendlist[a-1] = classes
        friendlist[b-1] = 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())
friends_set=set()
for i in range(M):
    a,b=map(int,input().split())
    if a>b:
        a,b=b,a
    friends_set.add((a,b)) 
    
friends_list=[[] for _ in range(N)]
for f in friends_set:
    friends_list[f[0]].append(f[1])

max_len=0
for i in friends_list:
    max_len=max(max_len,len(i)+1)
    
if N-max_len>=max_len:
    print(max_len)
else:
    print(max_len+1)

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

ngrp_max=1

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

    if grpno[p-1] > grpno[q-1]:
        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]

        if ngrp_max < ngrp[grpno[p-1]]:
            ngrp_max = ngrp[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(ngrp_max)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
# Union-Find
a=list(range(n))
def find(x):
  if a[x]==x:
    return x
  a[x] = find(a[x])
  return a[x]

for _ in range(m):
  x,y=map(lambda x:int(x)-1,input().split())
  a[y]=find(x)

count=[0]*n
for i in range(n):
  count[find(i)] += 1
print(max(count))

Submission status: Wrong Answer

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

from collections import defaultdict

# union find
class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n
 
    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1

uf = UnionFind(N)

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a > b:
        c = b
        b = a
        a = c

    uf.union(a, b)

# member = defaultdict(int)
r = min(uf.table)
if r != -1:
    mm = abs(r)
    ic = 0
    for n in uf.table:
        if n == -1:
            ic += 1

    if mm < ic:
        mm += 1
else:
    mm = 1

print(mm)

Submission status: Wrong Answer

Solution code:
#abc177_D_1
int_n, int_m = map(int, input().split())
list_agg = list()
for i in range(int_m):
  list_tmp = list(map(int, input().split()))
  list_agg.append(list_tmp)

int_max_len = 0
for iter_n in range(1, int_n+1):
  list_tmp_add = list()
  for i_list in list_agg:
    if iter_n in i_list:
      list_tmp_add = list_tmp_add + i_list
  len_n_lenght = len(list(set(list_tmp_add)))
  if len_n_lenght > int_max_len:
    int_max_len = len_n_lenght
    
print(int_max_len)

Submission status: Wrong Answer

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


friends=[{-1}]
num=1
people=[-1]*n
ans=0

F2=[]

for f in F:
    if f[0]<f[1]:
        F2.append(f)
    else:
        F2.append([f[1],f[0]])

F2.sort()

for f in F2:
    a=f[0]-1
    b=f[1]-1
    #print(a,b)

    if people[a]==-1 and people[b]==-1:
        friends.append({a,b})
        people[a]=num
        people[b]=num
        num+=1

    elif people[a]!=-1 and people[b]==-1:
        friends[people[a]].add(b)
        people[b]=people[a]

    elif people[a]==-1 and people[b]!=-1:
        friends[people[b]].add(a)
        people[a]=people[b]

    #print(people)
    #print(friends)

for i in friends:
    if len(i)>ans:
        ans=len(i)
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 = list(map(lambda x: int(x), 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)
                newGroup = set(group)
                newGroup.add(args[1])
                groupList.add(frozenset(newGroup))
                isHit = True
                break
            if (not hit0) and hit1:
                groupList.remove(group)
                newGroup = set(group)
                newGroup.add(args[0])
                groupList.add(frozenset(newGroup))
                isHit = True
                break

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

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

    print(maxNum)


if __name__ == "__main__":
    main()