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

G = []
lookup_tab = {}
inv_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})
        gid = len(G) - 1
        lookup_tab[a] = gid
        lookup_tab[b] = gid
        inv_tab[gid] = {a, b}
    elif a in lookup_tab:
        gid = lookup_tab[a]
        lookup_tab[b] = gid
        inv_tab[gid].add(b)
        G[gid].add(b)
    elif b in lookup_tab:
        gid = lookup_tab[b]
        lookup_tab[a] = gid
        inv_tab[gid].add(a)
        G[gid].add(a)
    else:
        a_gid = lookup_tab[a]
        b_gid = lookup_tab[b]
        if a_gid != b_gid:
            for k in inv_tab[b_gid]:
                lookup_tab[k] = a_gid
            G[a_gid] = G[a_gid] + G[b_gid]
        else:
            continue

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

Submission status: Wrong Answer

Solution code:
N, M = (int(x) for x in input().split())
import collections
Parent = [i for i in range(N)]
def fp(i):
    global Parent
    if Parent[i] == i:
        return i
    else:
        Parent[i] = fp(Parent[i])
        return Parent[i]

for _ in range(M):
    a, b = (int(x) for x in input().split())
    c, d = min(a,b)-1, max(a,b)-1
    Parent[d] = min(fp(c), fp(d))

Groupsize = collections.defaultdict(lambda:0)
for i in range(N):
    i = fp(i)
    Groupsize[i] +=1
ans = max(gs for gs in Groupsize.values())
print(ans)

Submission status: Wrong Answer

Solution code:
import networkx as nx

n,m=map(int,input().split())
a=[[tuple(i) for i in input().split()] for _ in range(m)]
g=nx.Graph()
g.add_edges_from(a)
m=0
for i in list(nx.connected_components(g)):
     m=max(m,len(i))
print(m)

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):
    if a[i] == [0]:
        continue
    for j in range(i + 1, m):
        if not set(a[i]).isdisjoint(set(a[j])):
            a[i].extend(a[j])
            a[j] = [0]
    a[i] = list(set(a[i]))
    max1 = max(max1, len(a[i]))
print(max1)

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 = [None] * (N + 1)
  for _ in range(N+1):
    friends.append(set())

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

    if friends[A] == None and friends[B] == None:
      num_of_friend[A] = 1
      num_of_friend[B] = 1
      friends[A] = set()
      friends[A].add(A)
      friends[A].add(B)
      friends[B] = set()
      friends[B].add(A)
      friends[B].add(B)
    elif friends[A] == None:
      friends[B].add(A)
      friends[A] = friends[B]
    elif friends[B] == None:
      friends[A].add(B)
      friends[B] = friends[A]
    else:
      union = friends[A] | friends[B]
      friends[A] = union
      friends[B] = union

    if len(friends[A]) > maximam_group:
      maximam_group = len(friends[A])

  # for friend in friends:
  #   print(friend)
  print(maximam_group)

if __name__ == "__main__":
  resolve()

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

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

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

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

Submission status: Wrong Answer

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

#AB = [tuple(map(int, input().split())) for i in range(M)]
#丸暗記。隣接リストの初期化
graph = [[i+1] for i in range(N)]

for _ in range(M):
  a, b = map(int, input().split())
  graph[a-1].append(b)
  graph[b-1].append(a)

ans = -1
for g in graph:
  ans = max(ans, len(set(g)))
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
lst = list(range(1, n+1))
dic = {x:set() for x in lst}
for i in range(m):
  a,b = map(int, input().split())
  dic[a].add(b)
  dic[b].add(a)
  set1 = dic[a]
  set2 = dic[b]
  for x,y in zip(dic[a],dic[b]):
      set1.add(b)
      set2.add(a)
  dic[a] = set1
  dic[b] = set2

res = len(dic[1])
for i in dic.values():
    if len(i) > res:
        res = len(i)
print(res + 1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import collections
class DJS:
    def __init__(self, n):
        self.p = defaultdict(int)
        self.rank = defaultdict(int)
        for i in range(n):
            self.makeSet(i)

    def makeSet(self,x):
        self.p[x] = x
        self.rank[x] = 0

    def findSet(self,x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]
    
    def unite(self, x, y):
        self.link(self.findSet(x),self.findSet(y))
    
    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
        

n,m = map(int,input().split())
djs = DJS(n)
for i in range(m):
    a,b = map(int,input().split())
    djs.unite(a-1,b-1)
tmp= collections.Counter(list(djs.p.values()))
ret = max(list(tmp.values()))
print(ret)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = list()
B = list()
for _ in range(M):
    a, b = map(int, input().split())
    A.append(a-1)
    B.append(b-1)

largest = 1
group = []
people = [-1] * N
for a, b in zip(A, B):
    if people[a] != -1 and people[b] != -1 and people[a] != people[b]:
        group[people[a]] |= group[people[b]]
        group[people[b]] = group[people[a]]
    elif people[a] != -1:
        people[b] = people[a]
        group[people[a]].add(b)
    elif people[b] != -1:
        people[a] = people[b]
        group[people[b]].add(a)
    else:
        group.append(set([a, b]))
        people[a] = len(group)-1
        people[b] = people[a]
    largest = max(len(group[people[a]]), largest)

print(largest)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

x = [[] for _ in range(N + 1)]
for a, b in AB:
    x[a].append(b)
    x[b].append(a)

for row in x:
    if len(row) >= 2:
        for v in combinations(row, 2):
            x[v[0]].append(v[1])
            x[v[1]].append(v[0])

l1 = []
l2 = [False] * (N + 1)
for i in range(1, N + 1):
    if l2[i]:
        continue
    l1.append([i])
    l2[i] = True
    for j in range(1, N + 1):
        if j == i or j in x[i] or l2[j]:
            continue
        else:
            l1[-1].append(j)
            l2[j] = 1
print(len(l1))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import math

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

n,m = readInts()
root = [i for i in range(n+1)]
ab = []
for i in range(m):
	a,b = sorted(readInts())
	root[b] = str(a)


for i in range(len(root)):
	while 1:
		if type(root[i]) is str:
			n = int(root[i])
			root[i] = root[n]
		else:
			break

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

Submission status: Wrong Answer

Solution code:

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


s = set()
L = []
ans = 0
for i in range(m):
    t1,t2 = map(int,input().split())
    if len(s) == 0:
        s.add(t1)
        s.add(t2)
    elif t1 in s or t2 in s:
        s.add(t1)
        s.add(t2)
    else:
        L.append([t1,t2])
else:
    ans = len(s)

#print(s,L,ans)

L2 = L
while len(L2) > 0:
    s = set() 
    L = []
    for i in range(m):
        t1= L2[0][0]
        t2= L2[0][1]
        if len(s) == 0:
            s.add(t1)
            s.add(t2)
        elif t1 in s or t2 in s:
            s.add(t1)
            s.add(t2)
        else:
            L.append([t1,t2])
    else:
        if ans < len(s):
            ans = len(s)
        L2 = L
#    print(L2)

print(ans)

Submission status: Wrong Answer

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

strab = []

for i in range(m):
  strab.append(input())

#strab.sort()

ab = []
for i in range(m):
  a , b = strab[i].split()
  if a < b:
    ab.append([int(a),int(b)])
  else :
    ab.append([int(b),int(a)])

ab.sort()
#print(ab)

num_friends = 0
friends = []
remain = list(range(m))

while True:  
  num_friends = max(len(friends),num_friends)
  
  if len(remain) == 0:
    break

  friends = []
  #print(remain)
  removelist = []
  for i in remain:
    # はじめの組み合わせなら、1番目を追加
    if friends == []:
      #print('から')
      friends.append(ab[i][0])
    if ab[i][0] in friends:
      #print('追加' + str(ab[i][1]))
      # 友達リストに組み合わせの２番目を追加する。
      friends.append(ab[i][1])
      # 残りリストからは消す。
      # remain.remove(i)
      removelist.append(i)
    else:
      pass
      #print('追加しない')
    #print('友達リスト' + str(friends))
  for i in removelist:
    remain.remove(i)
    
print(num_friends)
    
#print(strab)
#print(ab)

Submission status: Wrong Answer

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

mx=0
friends={}

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

for i in range(m):
    ab=input('').split()
    a = int(ab[0])
    b = int(ab[1])
    friends[a].add(b)
    for f in friends[a]:
        friends[f].add(b)
        friends[b].add(f)
   
for f in friends.values():
    len_f=len(f)
    if len_f > mx:
        mx=len_f
print(friends)
print(mx)

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):
    if groups[b] < groups[a]:
        groups[a] =  groups[b]
    else:
        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:
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 = [None] * (N + 1)
  for _ in range(N+1):
    friends.append(set())

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

    if friends[A] == None and friends[B] == None:
      num_of_friend[A] = 1
      num_of_friend[B] = 1
      friends[A] = set()
      friends[A].add(A)
      friends[A].add(B)
      friends[B] = set()
      friends[B].add(A)
      friends[B].add(B)
    elif friends[A] == None:
      friends[B].add(A)
      friends[A] = friends[B]
    elif friends[B] == None:
      friends[A].add(B)
      friends[B] = friends[A]
    else:
      union = friends[A] | friends[B]
      friends[A] = union
      friends[B] = union

    if len(friends[A]) > maximam_group:
      maximam_group = len(friends[A])

  # for friend in friends:
  #   print(friend)
  print(maximam_group)

if __name__ == "__main__":
  resolve()

Submission status: Wrong Answer

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

friends = [0]*n
group = [-1]*n

for a, b in ab:
    if a > b:
        a, b = b, a
    a -= 1
    b -= 1
    if group[a] == -1 and group[b] == -1:
        group[a] = a
        group[b] = b
        friends[a] += 2
    elif group[a] != -1 and group[b] != -1:
        group[b] = group[a]
        friends[group[a]] += friends[group[b]]
    elif group[a] == -1:
        group[a] = group[b]
        friends[group[b]] += 1
    elif group[b] == -1:
        group[b] = group[a]
        friends[group[a]] += 1

print(max(friends))

Submission status: Wrong Answer

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

ans = len(max(friends_set_list))

print(ans)

Submission status: Wrong Answer

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

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

A_set = set()
A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    if (a < b):
        A_set.add(a)
        A.append(a)
        B.append(b)
    else:
        A_set.add(b)
        A.append(b)
        B.append(a)


count = 0
member = []
for a in A_set:
    group = set()
    group.add(a)
    for i in range(M):
        if (A[i] == a):
            group.add(B[i])    
    member.append(len(group))
    count = count + 1

print(max(member))

Submission status: Wrong Answer

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

    groups = dict()
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        if a in groups:
            groups[a].add(b)
            groups[b] = groups[a]
        elif b in groups:
            groups[b].add(a)
            groups[a] = groups[b]
        else:
            groups[a] = set([a,b])
            groups[b] = groups[a]

    if M == 0:
        print(0)
        return

    x = groups.values()
    ans = max(map(len, groups.values()))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

table = [0] * (N + 1)

for i in range(M):
    tmp = list(map(int, input().split()))
    tmp.sort()
    if tmp[0] in friends:
        friends[tmp[0]].append(tmp[1])
    else:
        friends[tmp[0]] = [tmp[0], tmp[1]]

ans = 0

friends_list = list(friends.values())
for i in range(len(friends_list)):
    friends_list[i] = list(set(friends_list[i]))
    tmp = []
    for j in friends_list[i]:
        if j in friends:
            for k in friends[j]:
                tmp.append(k)
    tmp = list(set(tmp))
    for j in tmp:
        friends_list[i].append(j)
    friends_list[i] = list(set(friends_list[i]))

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

print(ans)

Submission status: Wrong Answer

Solution code:
N, M=map(int,input().split())
groupnumber=[0 for i in range(N)]
grouplist=[]
counter=0
maxmembers=0
for i in range(M):

  a,b=map(int,input().split())
  a-=1
  b-=1
  if groupnumber[a]==0 and groupnumber[b]==0:
    counter+=1
    groupnumber[a]=counter
    groupnumber[b]=counter
    
    grouplist+=[[a,b]]
  elif groupnumber[a]==0 and groupnumber[b]!=0:
    groupnumber[a]=groupnumber[b]
    tmp=groupnumber[a]-1
    grouplist[tmp]+=[a]
    
  elif groupnumber[a]!=0 and groupnumber[b]==0:
    groupnumber[b]=groupnumber[a]
    tmp=groupnumber[b]-1
    grouplist[tmp]+=[b]
  else:
    if groupnumber[a]!=groupnumber[b]:
      tmp1=groupnumber[a]-1
      tmp2=groupnumber[b]-1
      
      for i in grouplist[tmp2]:
        groupnumber[i]=tmp1
      if grouplist[tmp2]!=[] and grouplist[tmp2]!=[]:
        grouplist[tmp1]+=grouplist[tmp2]
        grouplist[tmp2]=[]
for i in grouplist:
  tmp=len(i)
  if tmp>maxmembers:
    maxmembers=tmp
print(maxmembers)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
#import sys
#sys.setrecursionlimit(2*10**5)

input = lambda : sys.stdin.readline().rstrip()

def main(pairs, n, m):
    gids = [None] * (n+1)

    graph = {}
    for node in range(1, n+1):
        graph[node] = []

    for a, b in pairs:
        graph[a].append(b)

    first = True
    next_gid = 0
    for a in range(1, n+1):
        bs = graph[a]

        if first:
            first = False
            cur_gid = next_gid
            gids[a] = cur_gid
            next_gid += 1
        else:
            if gids[a] is None:
                cur_gid = next_gid
                gids[a] = cur_gid
                next_gid += 1
            else:
                cur_gid = gids[a]

        for b in bs:
            gids[b] = cur_gid


    #print("gids", gids)

    #def get_gid(in_i, cur_gid):
    #    gids[in_i] = cur_gid
    #    kids = graph[in_i]
    #    for kid in kids:
    #        if gids[kid] is None:
    #            get_gid(kid, cur_gid)


    #cur_gid = 0
    #for i in range(1, n+1):
    #    if gids[i] is None:
    #        get_gid(i, cur_gid)
    #        cur_gid += 1

    #out = Counter(gids[1:]).most_common(1)[0][1]
    out = Counter(gids[1:]).most_common()[0][1]
    print(out)

if True:
    n, m = map(int, input().split(" "))
    pairs = set([tuple(sorted(map(int, input().split(" ")))) for i in range(m)])
else:
    import random
    n = random.randint(2, 2*10**5)
    m = random.randint(0, 2*10**5)
    pairs = set([tuple(sorted([random.randint(1, n), random.randint(1, n)])) for i in range(m)])

main(pairs, n, m)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M = map(int, input().split())
l = [[] for i in range(N)]
for i in range(M):
        a, b = map(int, input().split())
        l[a - 1].append(b - 1)
        l[b - 1].append(a - 1)
m = 0 
for i in range(N):
        if set(l[i]):
                l[i] = set(l[i])    
queue = deque([0])
c = []
while queue:
        now = queue.popleft()
        c.append(now)
        d = 0 
        for i in l[now]:
                if i in c:
                        continue
                else:
                        d += 1
                        queue.append(i)
        m = max(m, d)

print(m + 1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
lsa = [{i} for i in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    lsa[a] = lsa[a] | lsa[b]
    lsa[b] = lsa[a] | lsa[b]
ans = 0
for i in range(N+1):
    ans = max(ans,len(lsa[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N,M = map(int,input().split())
fr = []
for i in  range(N):
    fr.append(i+1)
for i in range(M):
    A,B =map(int,input().split())
    if A>B:
        fr[A-1]=fr[B-1]
    if A<B:
        fr[B-1]=fr[A-1]
c = collections.Counter(fr)
print(c.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    n, m = map(int,input().split())
    a = [0] * m
    b = [0] * m
    chokusetsu_friend = [[0 for i in range(n)] for j in range(n)]
    for i in range(m):
        a[i], b[i] = map(int, input().split())
        #A = chokusetsu_friend[a[i] - 1][b[i] - 1]
        chokusetsu_friend[a[i] - 1][b[i] - 1] = 1
        #B = chokusetsu_friend[b[i] - 1][a[i] - 1]
        chokusetsu_friend[b[i] - 1][a[i] - 1] = 1
    #print(i,chokusetsu_friend)
    ans = n
    for j in range(n):
        #print(chokusetsu_friend[i].count)
        if chokusetsu_friend[j].count(1) + 1 < ans:
            ans = chokusetsu_friend[j].count(1) + 1
    print(ans)




    #それぞれの友達を数える最も友達が多い人を見つけるその人たちをばらばらにする
    #最も友達が多い人の友達数タス1が答え
    #for i in range(m):





    

    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque


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


N, M = LI()
friend = [set() for _ in range(N)]
ans = 0
miru = set()
if M == 0:
    print(0)
    sys.exit()
for i in range(M):
    a, b = map(int, input().split())
    friend[a-1].add(b-1)
    friend[b-1].add(a-1)
    miru.add(a-1)
    miru.add(b-1)
looked = [0]*N
d = deque()
count = 1
d.append(a-1)
miru.discard(a-1)
while d:
    x = d.pop()
    for i in friend[x]:
        if looked[i] != 0:
            continue
        count += 1
        looked[i] = 1
    if len(d) == 0:
        ans = max(count, ans)
        if len(miru) == 0:
            break
        y = list(miru)
        d.append(y[0])
        looked[y[0]] = 1
        count = 1
        miru.discard(y[0])


print(ans)

Submission status: Wrong Answer

Solution code:
fst_line = input().split(" ")
p_num = int(fst_line[0])
joken_num = int(fst_line[1])

if joken_num == 0:
    print(1)

else:
    joken_list = []
    for i in range(joken_num):
        temp = input().split(" ")
        temp_list = [int(n) for n in temp]
        if(temp_list[1] < temp_list[0]):
            tmp = temp_list[1]
            temp_list[1] = temp_list[0]
            temp_list[0] = tmp
        
        temp_line = (str(temp_list[0])+" "+str(temp_list[1]))
        
        joken_list.append(temp_line)
    
    joken_list.sort()
    #print(joken_list)
    
    del_list=[]
    for i in range(joken_num - 1):
        if(joken_list[i]==joken_list[i+1]):
            del_list.append(i+1)
    del_list.sort(reverse = True)
    for i in range(len(del_list)):
        del joken_list[del_list[i]]
    
    #print(joken_list)
    
    group_list = []
    for i in range(p_num):
        group_list.append(i)
        
    num_joken_list = []
    for i in range(len(joken_list)):
        temp = joken_list[i].split(" ")
        temp_list = []
        temp_list.append(int(temp[0]))
        temp_list.append(int(temp[1]))
        num_joken_list.append(temp_list)
        
    #print(num_joken_list)
    num_joken_list.sort()
    
    #print(group_list)
    for i in range(len(num_joken_list)):
        a = num_joken_list[i][0]
        b = num_joken_list[i][1]
        #print(a,end=" ")
        #print(b)
        #print(group_list[b - 1],end=" ")
        group_list[b - 1] = group_list[a - 1]
        #print(group_list[b - 1])    
        
    group_list.sort()
    #print(group_list)
    
    max_num = 1
    temp = 1
    for i in range(p_num - 1):
        if group_list[i]==group_list[i+1]:
            temp +=1
        else:
            if temp > max_num:
                max_num = temp
            temp = 1
    
    if temp > max_num:
        max_num = temp
        
    print(max_num)

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:
        c = friendlist[a-1]
        friendlist[b-1] = c
    elif friendlist[b-1]!=0:
        d = friendlist[b-1]
        friendlist[a-1] = d
    else:
        friendlist[a-1] = classes
        friendlist[b-1] = classes
        classes += 1

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(99999999)


[n,m]=list(map(int,input().split()))
friends=[]
for i in range(m):
    friends.append(list(map(int,input().split())))

tomodachi=[[]for i in range(n)]

for i in range(m):
    tomodachi[friends[i][0]-1].append(friends[i][1]-1)
    tomodachi[friends[i][1]-1].append(friends[i][0]-1)

for i in range(n):
    tomodachi[i]=list(set(tomodachi[i]))

namelist=[1 for i in range(n)]
teams=[]

def haba(x,kari,tomodachi,namelist):
    for i in range(len(tomodachi[x])):
        if namelist[tomodachi[x][i]]==1:#生き残っているなら
            kari.append(tomodachi[x][i])
            namelist[tomodachi[x][i]]=0#殺す
            haba(tomodachi[x][i],kari,tomodachi,namelist)
    return(kari)
            


for i in range(n):
    if namelist[i]==1:
        teams.append(haba(i,[i],tomodachi,namelist))

saidai=99999999

for i in range(len(teams)):
    if saidai<len(teams[i]):
        saidai=len(teams[i])

ans=saidai

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
graph = [set({_}) for _ in range(n)]
for _ in range(m):
    #print(graph)
    a, b = map(int, input().split())
    used = set()
    graph[a-1].add(b-1)
    for g in graph[a-1]:
        used.add(g)
        graph[g].add(b-1)
    for g in graph[b-1]:
        graph[g] = graph[g].union(used)
      # 有向グラフなら消す
max_g = 0
for g in graph:
    if len(g)>max_g:
        max_g = len(g)
print(max_g)

Submission status: Wrong Answer

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

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

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

i = 1

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.append(2)
        i += 1
    elif g_idx[a] and not g_idx[b]:
        idx = g_idx[a]
        g_idx[b] = idx
        g_sum[idx] += 1
    elif g_idx[b] and not g_idx[a]:
        idx = g_idx[b]
        g_idx[b] = idx
        g_idx[a] = idx
        g_sum[idx] += 1
    else:
        mrg.append([g_idx[a], g_idx[b]])

g_inc = [[]] * (len(g_sum)+1)
mg_sum = g_sum
for g1, g2 in mrg:
    if g1 < g2:
        if g2 not in g_inc[g1]:
            g_inc[g1].append(g2)
            mg_sum[g1] += g_sum[g2]
    elif g2 < g1:
        if g1 not in g_inc[g2]:
            g_inc[g2].append(g1)
            mg_sum[g2] += g_sum[g1]

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

print(mx)

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

checker = []

detacheck = [0 for _ in range(N)]


#for AB in ABs:
#    checker[AB[0] - 1].add(AB[1])
#    checker[AB[1] - 1].add(AB[0])

tmp = 0
for AB in ABs:
#    print(detacheck)
    if(detacheck[AB[0] -1] == 0 and detacheck[AB[1] -1] == 0):
        checker.append(set(AB))
        tmp += 1
        detacheck[AB[0] - 1] = tmp
        detacheck[AB[1] - 1] = tmp


    elif(detacheck[AB[0] -1] == 0 or detacheck[AB[1] -1] == 0):
#        print(detacheck[AB[0] -1] , detacheck[AB[1] -1])
        checker[max(detacheck[AB[0] -1]-1,detacheck[AB[1] -1]-1)].add(AB[0])
        checker[max(detacheck[AB[0] -1]-1,detacheck[AB[1] -1]-1)].add(AB[1])

        detacheck[AB[0] - 1] = max(detacheck[AB[0] - 1],detacheck[AB[1] - 1])
        detacheck[AB[1] - 1] = max(detacheck[AB[0] - 1],detacheck[AB[1] - 1])

    else:
#        print(AB[0], AB[1])
        checker[detacheck[AB[0] -1]-1] = checker[detacheck[AB[0] -1]-1].union(checker[detacheck[AB[1] -1]-1])

#    print(checker)


ans = 1

for anscheck in checker:
#    print(anscheck, len(anscheck))
    ans = max(ans, len(anscheck))


print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
lsa = [{i} for i in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    lsa[a] = lsa[a] | lsa[b]
    lsa[b] = lsa[a] | lsa[b]
ans = 0
for i in range(N+1):
    ans = max(ans,len(lsa[i]))
print(lsa)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
lis = set()
cnt = [0]*(N+1)
for i in range(M):
    A,B = map(int,input().split())
    A,B = min(A,B),max(A,B)
    if not((A,B) in lis):
        cnt[A] += 1
        cnt[B] += 1
    lis.add((A,B))
print(max(cnt)+1)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m = map(int, input().split())
ab = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)

ans = 0
n_set = set([i for i in range(n)])
while n_set:
    g = set()
    cnt = 0
    queue = deque([list(n_set)[0]])
    while queue:
        now = queue.popleft()
        if now in g:
            continue
        g.add(now)
        cnt += 1
        for i in ab[now]:
            queue.append(i)
            g.add(i)
            cnt += 1
    ans = max(ans, cnt)
    n_set -= g
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)]
    List2 = [[] for i in range(N)]
    host = 0
    guest = 0
    for i in range(M):
        a = A[i][0]-1
        b = A[i][1]-1
        if List[a] == -1 and List[b] == -1:
            host = a
            guest = b
            List[host] = host
            List2[host].append(host)
            List[guest] = host
            List2[host].append(guest)
        elif List[a] != -1 and List[b] != -1 and List[a] != List[b]:
            host = List[a]
            guest = b
            for l in List2[List[b]]:
                List[l] = host
            List[guest] = host
            List2[List[a]].extend(List2[List[b]])
            List2[List[b]] = []
        elif List[a] != -1:
            host = List[a]
            guest = b
            List[guest] = host
            List2[host].append(guest)
        elif List[b] != -1:
            host = List[b]
            guest = a
            List[guest] = host
            List2[host].append(guest)
        
    ans = [0 for i in range(N)]
    for i in range(N):
        L = List[i]
        if L != -1:
            ans[L] += 1
            
    print(max(ans))
        
    
if __name__ == '__main__':
    main()