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())
encountered = []
friends = [['a']]

for _ in range(M):
  a, b = map(int, input().split())
  a_enc = a in encountered
  b_enc = b in encountered
  
  if [a_enc, b_enc] == [False, False]:
    friends += [[a, b]]
    encountered += [a, b]
    
  elif [a_enc, b_enc] == [False, True]:
    for i in range(len(friends)):
      if b in friends[i]:
        friends[i] += [a]
        break
    encountered += [a]
    
  elif [a_enc, b_enc] == [True, False]:
    for i in range(len(friends)):
      if a in friends[i]:
        friends[i] += [b]
        break
    encountered += [b]
   
  else:
    a_loc, b_loc = 0, 0
    for i in range(len(friends)):
      if a in friends[i]:
        a_loc == i
      if b in friends[i]:
        b_loc == i
      if a_loc != 0 and b_loc != 0:
        break
    if a_loc != b_loc:
      friends[a_loc] += friends[b_loc]
      del friends[b_loc]

print(max(map(len, friends)))

Submission status: Wrong Answer

Solution code:
from collections import Counter

class UnionFind():
    def __init__(self,n):
        
        self.parents = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if self.rank[x] < self.rank[y]:
            self.parents[x] = y
        else:
            self.parents[y] = x
            
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

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

uf = UnionFind(n)

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

c = Counter(uf.parents)

print(max(c.values()))

Submission status: Wrong Answer

Solution code:
N,M=input().split(' ')
n,m=int(N),int(M)

flist=[input().split(' ')for i in range(m)]
Alist=[int(0)for i in range(n)]
num=0
for i in range(m):
    a_i,b_i=int(flist[i][0]),int(flist[i][1])
    if Alist[a_i-1]==0 and Alist[b_i-1]==0:
        num+=1
        Alist[a_i-1]=num
        Alist[b_i-1]=num
    elif Alist[a_i-1]!=0:
        Alist[b_i-1]=Alist[a_i-1]
    elif Alist[b_i-1]!=0:
        Alist[a_i-1]=Alist[b_i-1]
print(num)

Submission status: Wrong Answer

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

I = [-1] * (n+1)
x = [] 
for _ in range(m):
    a,b = map(int, input().split())
    if x == []:
        x.append([a,b])
        I[a]=I[b]=0
    else:
        if I[a]==I[b]==-1:
            x.append([a,b])
            I[a]=I[b]=len(x)-1
        elif I[a] == -1:
            x[I[b]].append(a)
            I[a] = I[b]
        elif I[b] == -1:
            x[I[a]].append(b)
            I[b] = I[a]

ans = 1
if x != []:
    for i in x: ans = max(ans, len(i))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def solve(n, m, a, b):
    parents = list(range(n+1))
    def root(x):
        return root(parents[x]) if parents[x] != x else x
    for u, v in zip(a, b):
        u = root(u)
        v = root(v)
        if u > v:
            u, v = v, u
        if u != v:
            parents[v] = u
    return max(Counter(parents).values())

n, m = map(int, input().split())
if m > 0:
    a, b = zip(*[map(int, input().split()) for i in range(m)])
else:
    a, b = [], []
print(solve(n, m, a, b))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
f = [int(i) for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a > b:
        a, b = b, a
    f[b] = f[a]
print(max(f.count(i) for i in set(f)))

Submission status: Wrong Answer

Solution code:
class UnionFind:

    def __init__(self):
        self.parents = {}
        self.sz = {}
        self.size = 0


    def add(self, a):
        if a in self.parents:
            return
        self.size += 1
        self.sz[a] = 1
        self.parents[a] = a 

    def find(self, a):
        if self.parents[a] != a:
            self.parents[a] = self.find(self.parents[a])

        return self.parents[a]

    def join(self, a, b):
        pa, pb = self.find(a), self.find(b)
        if pa == pb:
            return
        if self.sz[pa] > self.sz[pb]:
            self.parents[pb] = pa
            self.sz[pa] += self.sz[pb]
        else:
            self.parents[pa] = pb 
            self.sz[pb] += self.sz[pa]

        self.size -= 1


n,m = list(map(int,input().split(" ")))
uf = UnionFind()
ans = 0
if m == 0:
    print(0)
else:
    for _ in range(m):
        x,y = list(map(int,input().split(" ")))
        uf.add(x)
        uf.add(y)
        uf.join(x,y)
        ans = max(ans, uf.sz[x])

    print(max(uf.sz.values()))

Submission status: Wrong Answer

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

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

id_list = [-1]*n


def dfs(friends, start):
    d = deque()
    group_count = 0
    if id_list[start] == -1:
        id_list[start] = start
        d.append(start)
        group_count += 1
    while d:
        p = d.pop()
        for child in friends[p]:
            if id_list[child] != -1:
                continue
            group_count += 1
            id_list[child] = start
    return group_count

max_friend = 0
for i in range(n):
    max_friend = max(max_friend, dfs(friends, i))
print(max_friend)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
dic = {}
for i in range(n):
    dic[i+1]=set()
    
for _ in range(m):
    a,b = map(int,input().split())
    dic[a].add(b)
    dic[b].add(a)

max_num = 0
registerd_set = set()
for i in range(1,n+1):
    if i in registerd_set:
        continue
    else:
        people_list = [i]
        registerd_set.add(i)
    count = 0
    for people in people_list:
        count += 1
        for friend in dic[people]:
            if friend not in registerd_set:
                registerd_set.add(people)
                people_list.append(friend)
    if max_num < count:
        max_num = count
print(max_num)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
dic = {}
for i in range(n):
    dic[i+1]=set()
    
for _ in range(m):
    a,b = map(int,input().split())
    dic[a].add(b)
    dic[b].add(a)

max_num = 0
registerd_set = set()
for i in range(1,n+1):
    if i in registerd_set:
        continue
    else:
        people_list = [i]
    count = 0
    for people in people_list:
        count += 1
        registerd_set.add(people)
        for friend in dic[people]:
            if friend not in registerd_set:
                people_list.append(friend)
    if max_num < count:
        max_num = count
print(max_num)

Submission status: Wrong Answer

Solution code:
import sys

ans=0
g=set()
input()
for s in sys.stdin:
    d=set()
    for a in s.split():
        a=' '+a
        for u in g:
            if a in u:
                d.add(u)
                s+=u
    g^=d
    g.add(' '+s)

if g:
    print(max(len(set(t.split())) for t in g))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys

ans=0
g=set()
input()
for s in sys.stdin:
    d=set()
    for a in s.split():
        for u in g:
            if a in u:
                d.add(u)
                s+=u
    g^=d
    g.add(' '+s)

if g:
    print(max(len(set(t.split())) for t in g))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys

ans=0
g=set()
input()
for s in sys.stdin:
    for a in s.split():
        for u in [*g]:
            if a in u:
                g.discard(u)
                s+=u
    g.add(s)

if g:
    print(max(len(set(t.split())) for t in g))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N, M=map(int, input().split())
A=[]
B=[]
for i in range(M):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)
# AB= [map(int, input().split()) for _ in range(M)]
# A, B = [list(i) for i in zip(*AB)]

G=[0]*(N+1)
for i in range(M):
    ga=G[A[i]]
    gb=G[B[i]]
    if ga==0 and gb==0:
        G[A[i]]=max(G)+1
        G[B[i]]=G[A[i]]
    elif ga==0:
        G[A[i]]=gb
    elif gb==0:
        G[B[i]]=ga
    elif gb>ga:
        for j in range(len(G)):
            if G[j]==gb:
                G[j]=ga
    elif ga>gb:
        for j in range(len(G)):
            if G[j]==ga:
                G[j]=gb        
G=G[1:]
import collections
c=collections.Counter(G)
print(int(c.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
N, M=map(int, input().split())
A=[]
B=[]
for i in range(M):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)
# AB= [map(int, input().split()) for _ in range(M)]
# A, B = [list(i) for i in zip(*AB)]

G=[0]*(N+1)
sw=1
for i in range(M):
    if G[A[i]]==0 and G[B[i]]==0:
        G[A[i]]=sw
        G[B[i]]=sw
        sw+=1
    elif G[A[i]]==0:
        G[A[i]]=G[B[i]]
    elif G[B[i]]==0:
        G[B[i]]=G[A[i]]
G=G[1:]
import collections
c=collections.Counter(G)
print(int(c.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
N, M=map(int, input().split())
A=[]
B=[]
for i in range(M):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)
# AB= [map(int, input().split()) for _ in range(M)]
# A, B = [list(i) for i in zip(*AB)]

G=[0]*(N+1)
sw=1
for i in range(M):
    if G[A[i]]+G[B[i]]==0:
        G[A[i]]=sw
        G[B[i]]=sw
        sw+=1
    elif G[A[i]]==0:
        G[A[i]]=G[B[i]]
    elif G[B[i]]==0:
        G[B[i]]=G[A[i]]
G=G[1:]
import collections
c=collections.Counter(G)
print(int(c.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter


class UnionFind:
    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
        else:
            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 x == y:
            return

        if self.par[x] > self.par[y]:
            x, y = y, x

        self.par[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def same_check(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.union(a, b)

ans = max(Counter(uf.par).values())

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


class UnionFind:
    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
        else:
            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 x == y:
            pass
        elif 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

    def same_check(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.union(a, b)

ans = max(Counter(uf.par).values())

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


class UnionFind:
    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
        else:
            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

    def same_check(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.union(a, b)

c = Counter(uf.par)
ans = c.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


class UnionFind:
    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
        else:
            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 x == y:
            pass
        elif 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

    def same_check(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.union(a, b)

if M == 0:
    ans = 1
else:
    c = Counter(uf.par)
    ans = c.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
class Node():
    def __init__(self,index):
        self.index = index
        self.parent = self 
        self.size = 1

    @staticmethod
    def find_set(node):
        return node
        if node.parent == node:
            return node 
        root = Node.find_set(node.parent)
        node.parent = root
        root.size += 1
        return root

    @staticmethod
    def union(node_a,node_b):
        root_a = Node.find_set(node_a)
        root_b = Node.find_set(node_b)
        if root_a != root_b:
            if root_a.size < root_b.size:
                root_a.parent = root_b
            else:
                root_b.parent = root_a



if __name__ == "__main__":
    n,m = [int(val) for val in input().split()]
    
    persons = []
    count = []
    for i in range(n):
        persons.append(Node(i))
        count.append(0)
    
    for i in range(m):
        a,b = [int(val) for val in input().split()]
        if a > b:
            Node.union(persons[a-1],persons[b-1])
        else:
            Node.union(persons[b-1],persons[a-1])


    for idx,person in enumerate(persons):
        count[Node.find_set(person).index] += 1
    
    # print(count)
    result = max(count)
    print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter


class UnionFind:
    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
        else:
            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 x == y:
            pass
        elif 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

    def same_check(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.union(a, b)

c = Counter(uf.par)
ans = c.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main(N, M, C):
    lst = [n for n in range(N)]

    def get_root(x):
        if lst[x] == x:
            return x
        else:
            lst[x] = get_root(lst[x])
            return lst[x]

    def is_same(x, y):
        return get_root(x) == get_root(y)

    def unite(x, y):
        if x > y:
            m = y
            M = x
        else:
            m = x
            M = y
        lst[M] = get_root(m)

    get_index = lambda x, y:(x-1, y-1)

    for c in C:
        indexes = get_index(*c)
        if not is_same(*indexes):
            unite(*indexes)
    # print(lst)
    print(max(Counter(lst).values()))


if __name__ == '__main__':
    N, M = list(map(int, input().split()))
    C = set()
    for _ in range(M):
        C.add(tuple(map(int, input().split())))
    main(N, M, C)

Submission status: Wrong Answer

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

for i in range(m):
	ab=sorted(list(map(int, input().split())))
	a,b=ab[0]-1, ab[1]-1
	while True:
		if len(ans[a])>1:
			break
		if ans[a][0]<a:
			a=ans[a]
		else:
			break
	ans[a]+=ans[b]
	ans[a]=list(set(ans[a]))
max_num=0
for i in range(n):
	max_num=max(len(ans[i]), max_num)
print(max_num)

Submission status: Wrong Answer

Solution code:
N, M=map(int, input().split())
A=[]
B=[]
for i in range(M):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)
# AB= [map(int, input().split()) for _ in range(M)]
# A, B = [list(i) for i in zip(*AB)]

G=[0]*(N+1)
sw=1
for i in range(M):
    if G[A[i]]+G[B[i]]==0:
        G[A[i]]=sw
        G[B[i]]=sw
        sw+=1
    elif G[A[i]]==0:
        G[A[i]]=G[B[i]]
    elif G[B[i]]==0:
        G[B[i]]=G[A[i]]
G=G[1:]
import collections
c=collections.Counter(G)
print(c.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main(N, M, C):
    lst = [n for n in range(N)]

    def get_root(x):
        if lst[x] == x:
            return x
        else:
            lst[x] = get_root(lst[x])
            return lst[x]

    def is_same(x, y):
        return get_root(x) == get_root(y)

    def unite(x, y):
        lst[x] = get_root(y)

    get_index = lambda x, y:(x-1, y-1)

    for c in C:
        indexes = get_index(*c)
        if not is_same(*indexes):
            unite(*indexes)
    print(max(Counter(lst).values()))


if __name__ == '__main__':
    N, M = list(map(int, input().split()))
    C = set()
    for _ in range(M):
        C.add(tuple(map(int, input().split())))
    main(N, M, C)

Submission status: Wrong Answer

Solution code:
N, M=map(int, input().split())
A=[]
B=[]
for i in range(M):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)
# AB= [map(int, input().split()) for _ in range(M)]
# A, B = [list(i) for i in zip(*AB)]

G=[0]*(N+1)
sw=1
for i in range(M):
    if G[A[i]]+G[B[i]]==0:
        G[A[i]]=sw
        G[B[i]]=sw
        sw+=1
    if G[A[i]]!=0:
        G[B[i]]=G[A[i]]
    else:
        G[A[i]]=G[B[i]]
G=G[1:]
import collections
c=collections.Counter(G)
print(c.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
class Tree:
    def __init__(self, n):
        self.parent = []
        self.rank = []
        for i in range(n+1):
            self.parent.append(i)
            self.rank.append(0)

def findRoot(x, tree):
    if tree.parent[x] == x:
        return x
    else:
        tree.parent[x] = findRoot(tree.parent[x], tree)
        return tree.parent[x]
    
def uniteRoot(x, y, tree):
    x = findRoot(x, tree)
    y = findRoot(y, tree)
    if x == y:
        return
    if tree.rank[x] == tree.rank[y]:
        tree.parent[x] = y
    else:
        tree.parent[y] = x
        if tree.rank[x] == tree.rank[y]:
            tree.rank[x] = tree.rank[x]+1

def sameRoot(x, y, tree):
    return findRoot(x, tree) == findRoot(y,tree)

N, M = list(map(int, input().split()))
A = []
for i in range(N+1):
    A.append(0)

tree = Tree(N)

if M == 0:
    print(1)
else:
    for i in range(M):
        j, k = list(map(int, input().split()))
        uniteRoot(j, k, tree)
    for m in range(1, N+1, 1):
        A[tree.parent[m]] += 1
    print(max(A))

Submission status: Wrong Answer

Solution code:
class Node():
    def __init__(self,index):
        self.root = index 

    def join(self,target):
        self.root = target.root

if __name__ == "__main__":
    n,m = [int(val) for val in input().split()]
    
    persons = []
    count = []
    for i in range(n):
        persons.append(Node(i))
        count.append(0)
    
    for i in range(m):
        a,b = [int(val) for val in input().split()]
        if a > b:
            persons[a-1].join(persons[b-1])
        else:
            persons[b-1].join(persons[a-1])
    
    for idx,person in enumerate(persons):
        count[person.root] += 1
    
    result = max(count)
    print(result)

Submission status: Wrong Answer

Solution code:
class Tree:
    def __init__(self, n):
        self.parent = []
        self.rank = []
        for i in range(n+1):
            self.parent.append(i)
            self.rank.append(0)

def findRoot(x, tree):
    if tree.parent[x] == x:
        return x
    else:
        tree.parent[x] = findRoot(tree.parent[x], tree)
        return tree.parent[x]
    
def uniteRoot(x, y, tree):
    x = findRoot(x, tree)
    y = findRoot(y, tree)
    if x == y:
        return
    if tree.rank[x] == tree.rank[y]:
        tree.parent[x] = y
    else:
        tree.parent[y] = x
        if tree.rank[x] == tree.rank[y]:
            tree.rank[x] = tree.rank[x]+1

def sameRoot(x, y, tree):
    return findRoot(x, tree) == findRoot(y,tree)

N, M = list(map(int, input().split()))
A = []
for i in range(N+1):
    A.append(0)

tree = Tree(N)

if M == 0:
    print(1)
else:
    for i in range(M):
        j, k = list(map(int, input().split()))
        uniteRoot(j, k, tree)
# print(sameRoot(1, 3, tree))
# print(tree.parent)
# print(max(A))
for m in range(1, N+1, 1):
    A[tree.parent[m]] += 1
    
# print(A)
print(max(A))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

def main():

    N,M = map(int,input().split())
    X = [list(map(int,input().split())) for _ in range(M)]
    '''
    import random
    N = 4 * 10**4 
    M = N - 1
    X = [[random.randint(1,N),random.randint(1,N)] for i in range(M)] 
    '''        
    Y = [-1 for _ in range(N+1)]
    Z = [[] for _ in range(N+1)]
    '''
    # 前処理　大小関係の整理と重複の削除
    for x in X:
        a = x[0]
        b = x[1]
        if a == b:
            X.remove(x)
        elif a > b:
            x[0],x[1] = b,a
            
    X.sort()
    for i in reversed(range(len(X)-1)):
        if X[i+1]==X[i]:
            X.pop(i+1)
    '''
    if M==0:
        print(1)
    else:
        for x in X:
            a = x[0]
            b = x[1]
            if Y[a] == -1:
                if Y[b] == -1:
                    Y[a] = Y[b] = a
                    Z[a] = [a,b]
                else:
                    Y[a] = Y[b]
                Z[Y[b]] += [a]
            else:
                if Y[b] == -1:
                    Y[b] = Y[a]
                    Z[Y[a]] += [b]
                else:
                    ya = Y[a]
                    yb = Y[b]
                    if ya != yb:
                        for y in Z[Y[b]]:
                            Y[y] = ya
                        Z[ya] += Z[yb]
                        Z[yb].clear()
            #print(x,Y,Z)
        
        Yf = set(Y)
        Yf.remove(-1)
        maxc = 0
        for i in Yf:
            maxc = max(maxc,len(Z[i]))
        print(maxc)
    
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(m):
	ab=sorted(list(map(int, input().split())))
	ab=[ab[0]-1, ab[1]-1]
	if not ab[1] in ans[ab[0]]:
		ans[ab[0]].append(ab[1])
	if ans[ab[1]]!=[]:
		ans[ab[1]]=[]
max_num=0
for i in range(n):
	max_num=max(len(ans[i]), max_num)
print(max_num)

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 and b in groups:
            groups[a] = groups[a] | groups[b]
            groups[b] = groups[a]
        elif 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(1)
        return

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import *
n,m = map(int,input().split())
par = [-1 for _ in range(n)]#par<0なら自身が親で要素の個数、>0なら子で親の位置示す

def root(i):
    if par[i] < 0:
        return i
    else:
        return root(par[i])

def size(a):
    return -par[root(a)]

def union(a,b):
    a = root(a)
    b = root(b)
    if a == b:#親が等しい
        return False
    if size(a) < size(b):#サイズが大きい方に繋げる
        a,b = b,a
    par[a] += par[b]
    par[b] = a
    return True

for i in range(m):
    a = [int(j)-1 for j in input().split()]#数字を一つ減らして足を揃える
    if root(a[0]) != root(a[1]):
        union(a[0],a[1])

print(Counter(par).most_common()[0][1]+1)

Submission status: Wrong Answer

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

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

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


info = tuple(set(info))

comp = [[info[0][0],info[0][1]]]
for i in range(len(info)):
    for k,group in enumerate(comp):
        if info[i][0] in group and info [i][1] in group:
            break
        elif info[i][0] in group:
            group.append(info[i][1])
            break
        elif info[i][1] in group:
            group.append(info[i][0])
            break
        if k+1 == len(comp):
            comp.append([info[i][0],info[i][1]])
    
max_n = 0    
for group in comp:
    max_n = max(len(group), max_n)
    
print(max_n)

Submission status: Wrong Answer

Solution code:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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

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

ans = 0

for i in range(N):
    ans = max(ans, uf.size(i))

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 and b in groups:
            groups[a] = groups[a] | groups[b]
            groups[b] = groups[a]
        elif 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:
import copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *
from collections import deque


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# a_list = [0] * a
sys.setrecursionlimit(10 ** 6)

def main():
    start = time.time()

    n, m = get_int_multi()

    a = [-1] * n
    b = [0] * n
    c = [-1] * n

    bidx = 0
    for _ in range(m):
        f1, f2 = get_int_multi()
        f1 -= 1
        f2 -= 1

        if a[f1] == -1 and a[f2] == -1:
            bidx += 1
            a[f1] = bidx
            a[f2] = bidx
            b[bidx] = 2

        elif a[f1] == a[f2]:
            continue #なにもしない

        elif a[f1] != -1:
            if a[f2] != -1:
                if b[a[f2]] == 0:
                    b[a[f1]] += b[c[f2]]
                    b[c[f2]] = 0
                else:
                    b[a[f1]] += b[a[f2]]
                    b[a[f2]] = 0

                for ii in range(n):
                    if c[ii] == a[f2]:
                        c[ii] == a[f1]
                c[a[f2]] = a[f1]
            else:
                b[bidx] += 1
                a[f2] = a[f1]

        elif a[f2] != -1:
            #if a[f1] != -1:
            #    wk = a[f1]
            #    for i in range(n):
            #        if a[i] == wk:
            #            a[i] = a[f2]
            #else:
                b[bidx] += 1
                a[f1] = a[f2]

    b.sort(reverse=True)
    print(b[0])

    #print(time.time() - start)


if __name__ == '__main__':
    main()