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 deque

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

G = [[] for _ in range(N+1)]

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

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


d = deque()

for j in range(1,N+1):
    if dist[j] != -1:
        continue
    dist[j] = 0
    d.append(j)
    while d:
        x = 1
        v = d.popleft()
        for i in G[v]:
            if dist[i] != -1:
                continue
            x += 1
            dist[i] = dist[v] + 1
            d.append(i)
        mx = max(mx, x)

print(mx)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

G = [[] for _ in range(N+1)]

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

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

d = deque()

for j in range(1,N+1):
    if(j==1):
        dist[1] = 0
    else:
        if dist[j] != -1:
            continue
    d.append(j)
    while d:
        x = 1
        v = d.popleft()
        for i in G[v]:
            if dist[i] != -1:
                continue
            x += 1
            dist[i] = dist[v] + 1
            d.append(i)
        mx = max(mx, x)

print(mx)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

G = [[] for _ in range(N+1)]

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

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

d = deque()
d.append(1)

while d:
    x = 1
    v = d.popleft()
    for i in G[v]:
        if dist[i] != -1:
            continue
        x += 1
        dist[i] = dist[v] + 1
        d.append(i)
    mx = max(mx, x)

print(mx)

Submission status: Wrong Answer

Solution code:
N,M=list(map(int,input().split()))
X=[]
for i in range(M):
    X.append(list(map(int,input().split())))
dic={i:0 for i in range(1,N+1)}
for i in range(M):
    if dic[X[i][0]]==0 and dic[X[i][1]]==0:
        dic[X[i][0]]=i+1
        dic[X[i][1]]=i+1
    elif dic[X[i][0]]==0 and dic[X[i][1]]!=0:
        dic[X[i][0]]=dic[X[i][1]]
    elif dic[X[i][1]]==0 and dic[X[i][0]]!=0:
        dic[X[i][1]]=dic[X[i][0]]
    else:
        t=dic[X[i][0]]
        s=dic[X[i][1]]
        for k in dic.keys():
            if dic[k]==s:
                dic[k]=t

c=[]
for k in dic.values():
    count=0
    for j in dic.keys():
        if dic[j]==k:
            count=count+1
    c.append(count)

print(max(c))

Submission status: Wrong Answer

Solution code:
from sys import stdin
def I():
    return stdin.readline().rstrip()
def MI():
    return map(int,stdin.readline().rstrip().split())
def LI():
    return list(map(int,stdin.readline().rstrip().split()))
#main part
def main():
    n,m=MI()
    friends=[]
    if m==0:
        print(n)
    else:
        for _ in range(m):
            a,b=MI()
            if _==0:
                friends.append([a,b])
            else:
                for i in range(len(friends)):
                    if a in friends[i]:
                        if b not in friends[i]:
                            friends[i].append(b)
                        break
                    elif b in friends[i]:
                        friends[i].append(a)
                        break
                    friends.append([a,b])
        ans=0
        for i in range(len(friends)):
            if ans<len(friends[i]):
                ans=len(friends[i])
        print(ans)


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
V=[]
for _ in range(M):
    a,b=map(int,input().split())
    f=True
    for t in V:
        if a in t and b not in t:
            f=False
            t.append(a)
            break
        if a in t and b not in t:
            f=False
            t.append(b)
            break
    if f:
        V.append([a,b])
if M == 0:
    print(1)
else:
    print(max(map(len,V)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
dic = defaultdict(list)
N, M  = map(int, input().split())
for i in range(M):
    a, b = map(int, input().split())
    dic[a].append(b)
    dic[b].append(a)
ans = 0
now = 1
seen = [-1]*N
queue = deque()
queue.append(1)
seen[0]=now
for i in range(N):
    if seen[i-1]!=-1:
        continue
    temp=0
    while queue:
        temp+=1
        q = queue.popleft()
        for j in dic[q]:
            if seen[j-1]!=-1:
                continue
            queue.append(j)
            seen[j-1]=now
    now+=1
    ans = max(ans, temp)
    
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
V=[]
for _ in range(M):
    a,b=map(int,input().split())
    flg=True
    for v in V:
        if (a in v) or (b in v):
            if a not in v:
                v.append(a)
            if b not in v:
                v.append(b)
            flg=False
    if flg:
        V.append([a,b])
m=0
for v in V:
    m=max(m,len(v))
print(m)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy
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())
    uf.union(a-1, b-1)
print(max(numpy.abs(uf.parents)))

Submission status: Wrong Answer

Solution code:
N,M = (int(x) for x in input().split())
s = [{i} for i in range(1,N+1)]
for i in range(M):
  a,b = (int(x) for x in input().split())
  for j in range(len(s)):
    if {a,b}&s[j] :
      s[j] = {a,b}|s[j]
print(s)
s_len = [len(x) for x in s]
print(max(s_len))

Submission status: Wrong Answer

Solution code:
N,M = (int(x) for x in input().split())
s = [{i} for i in range(1,N+1)]
s_len = [len(x) for x in s]
for i in range(M):
  a,b = (int(x) for x in input().split())
  for j,st in enumerate(s):
    if {a,b}&st :
      st = {a,b}|st
print(max(s_len))

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.stats as stats
import collections
from collections import Counter

N=list(map(int,input().split()))
n=N[0]
m=N[1]
A = []
if m==0:
  print(1)
else:
  for i in range(m):
    array = list(map(int,input().split()))
    array.sort()
    A.append(array)
  tpA = map(tuple, A)
  pattern = tuple(set(tpA))
  t = map(tuple,pattern)
  
  def flatten_2dim(array):
    return [item for sublist in array for item in sublist]
  
  y = stats.mode(flatten_2dim(t))
  
  print(*(1+y[1]))

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.stats as stats
N=list(map(int,input().split()))
n=N[0]
m=N[1]
A = []
if m==0:
  print(n)
else:
  for i in range(m):
    array = list(map(int,input().split()))
    array.sort()
    A.append(array)
  tpA = map(tuple, A)
  pattern = tuple(set(tpA))
  
  
  import collections
  from collections import Counter
  t = map(tuple,pattern)
  
  def flatten_2dim(array):
    return [item for sublist in array for item in sublist]
  
  y = stats.mode(flatten_2dim(t))
  
  print(*(1+y[1]))

Submission status: Wrong Answer

Solution code:
def root(x):
  if par[x] == x:
    return x
  par[x] = root(par[x])
  return par[x]

def union(x, y):
  rx = root(x)
  ry = root(y)
  if rx != ry:
    par[rx] = ry
  return 0
    
n, m=map(int, input().split(" "))
par = list(range(n + 1))
for i in range(m):
  a, b = map(int, input().split(" "))
  union(a, b)
#print(par)
maxi = 0
count = 1
#print(par)
countpar = [0 for i in range(n + 3)]
for i in range(1, n + 1):
  countpar[i] += 1
print(max(countpar))

Submission status: Wrong Answer

Solution code:
def root(x):
  if par[x] == x:
    return x
  par[x] = 1
  return par[x]

def union(x, y):
  rx = root(x)
  ry = root(y)
  if rx != ry:
    par[rx] = ry
  return 0
    
n, m=map(int, input().split(" "))
par = list(range(n + 1))
for i in range(m):
  a, b = map(int, input().split(" "))
  union(a, b)
#print(par)
maxi = 0
count = 1
#print(par)
countpar = [0 for i in range(n + 1)]
for i in range(1, n + 1):
  countpar[root(par[i])] += 1
print(max(countpar))

Submission status: Wrong Answer

Solution code:
def root(x):
  return 1
  if par[x] == x:
    return x
  par[x] = root(par[x])
  return par[x]

def union(x, y):
  rx = root(x)
  ry = root(y)
  if rx != ry:
    par[rx] = ry
  return 0
    
n, m=map(int, input().split(" "))
par = list(range(n + 1))
for i in range(m):
  a, b = map(int, input().split(" "))
  union(a, b)
#print(par)
maxi = 0
count = 1
#print(par)
countpar = [0 for i in range(n + 1)]
for i in range(1, n + 1):
  countpar[root(par[i])] += 1
print(max(countpar))

Submission status: Wrong Answer

Solution code:
def root(x):
  if par[x] == x:
    return x
  par[x] = root(par[x])
  return par[x]

def union(x, y):
  rx = root(x)
  ry = root(y)
  if rx != ry:
    par[rx] = ry
  return 0
    
n, m=map(int, input().split(" "))
par = list(range(n + 1))
for i in range(m):
  a, b = map(int, input().split(" "))
  union(a, b)
#print(par)
maxi = 0
count = 1
#print(par)
countpar = [0 for i in range(n + 1)]
for i in range(1, n + 1):
  print(i)
print(max(countpar))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import random
import collections

class UnionFind:
    def __init__(self, n):
        self.par = [x for x in range(n)]
        
    def root(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]
        
    def unit(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return
        self.par[rx] = ry
        
    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx==ry

def main():
    n, m = map(int, input().split())
    # n = 2 * 10 ** 5
    # m = 2 * 10 ** 5
    matrix = []
    if m == 0:
        print(n)
        return
    
    uf = UnionFind(n)
    
    for _ in range(m):
        a, b = map(int, input().split())
        # a = random.randint(1, 2 * 10**5)
        # b = random.randint(1, 2 * 10**5)
        if a > b:
            a, b = b, a
        uf.unit(a-1, b-1)
        uf.same(a-1, b-1)
        # print(uf.par)
        
    # print(matrix) 
    
    # print(uf.same(0, 1))
    c = collections.Counter(uf.par)
    # print(uf.par)
    # print(c)
    ans = max(list(c.values()))
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import random
import collections

class UnionFind:
    def __init__(self, n):
        self.par = [x for x in range(n)]
        
    def root(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]
        
    def unit(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return
        self.par[rx] = ry
        
    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx==ry

def main():
    n, m = map(int, input().split())
    # n = 2 * 10 ** 5
    # m = 2 * 10 ** 5
    matrix = []
    if m == 0:
        print(n)
        return
    
    uf = UnionFind(n)
    
    for _ in range(m):
        a, b = map(int, input().split())
        # a = random.randint(1, 2 * 10**5)
        # b = random.randint(1, 2 * 10**5)
        # if a > b:
        #     a, b = b, a
        uf.unit(a-1, b-1)
        uf.same(a-1, b-1)
        # print(uf.par)
        
    # print(matrix) 
    
    # print(uf.same(0, 1))
    c = collections.Counter(uf.par)
    # print(uf.par)
    # print(c)
    ans = max(list(c.values()))
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    #n = int(stdin.readline().rstrip())
    n,m = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    graph = [[] for i in range(n)]
    for i in range(m):
        a,b = map(int, stdin.readline().rstrip().split())
        a-=1;b-=1 #indexに直す
        graph[a].append(b)
        graph[b].append(a)
    num = []
    for i in range(n):
        g = graph[i]
        num.append(len(set(g)))
    print(max(num) + 1)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import defaultdict

def main():
    n, m = map(int, input().split())
    matrix = []
    for _ in range(m):
        a, b = map(int, input().split())
        for i, row in enumerate(matrix):
            if a in row or b in row:
               matrix[i].append(a)
               matrix[i].append(b)
               break
        else:
            matrix.append([a, b])
            
    ans = 0
    for row in matrix:
        ans = max(ans, len(set(row)))
        
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)

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

tree = [-1] * N

def root(x):
  if tree[x] < 0:
    return x
  else:
    tree[x] = root(tree[x])
    return tree[x]

def unite(x, y):
  rx, ry = root(x), root(y)
  if rx == ry: return
  tree[rx] += tree[ry]
  tree[y] = rx

def size(x):
  return -tree[root(x)]

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

print(max(map(size, range(N))))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)

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

tree = [-1] * N

def root(x):
  if tree[x] < 0:
    return x
  else:
    tree[x] = root(tree[x])
    return tree[x]

def unite(x, y):
  rx, ry = root(x), root(y)
  if rx == ry: return
  tree[rx] += tree[ry]
  tree[y] = x

def size(x):
  return -tree[root(x)]

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

print(max(map(size, range(N))))

Submission status: Wrong Answer

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

tree = [-1] * N

def root(x):
  if tree[x] < 0:
    return x
  else:
    tree[x] = root(tree[x])
    return tree[x]

def unite(x, y):
  rx, ry = root(x), root(y)
  if rx == ry: return
  tree[rx] += tree[ry]
  tree[y] = x

def size(x):
  return -tree[root(x)]

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

print(max(map(size, range(N))))

Submission status: Wrong Answer

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

friends = []
for i in range(M):
    A, B = map(int, input().split())
    n = len(friends)
    if n == 0:
        friends.append({A, B})
    for i in range(n):
        if A in friends[i]:
            friends[i].add(B)
        elif B in friends[i]:
            friends[i].add(A)
        else:
            if i == n-1:
                friends.append({A, B})
ans = 0
for group in friends:
    ans = max(ans, len(group))

print(ans)

Submission status: Wrong Answer

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

l = list(range(1,N+1))

for _ in range(M):
  a,b = map(int,input().split())
  l[max(a,b)-1] = l[min(a,b)-1]
    
print(max([len([i for i in l if i == j]) for j in set(l)]))

Submission status: Wrong Answer

Solution code:
"""D."""

import sys
from typing import Dict, List


def input() -> str:  # noqa: A001
    """Input."""
    return sys.stdin.readline()[:-1]


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

rels: Dict[int, set] = {i + 1: set() for i in range(n)}

pairs = {tuple(map(int, input().split(' '))) for _ in range(m)}

for a, b in pairs:
    rels[a].add(b)
    rels[b].add(a)

samples = set(range(1, n + 1))
groups: List[Dict[str, set]] = []

for a in samples:
    join = False
    for g in groups:
        if a not in g['ng']:
            join = True
            g['n'].add(a)
            g['ng'] = g['ng'].union(rels[a])
    if not join:
        groups.append({
            'n': {a},
            'ng': rels[a],
        })

print(len(groups))

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

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

pairs = [0] * M
for i in range(M):
    pairs[i] = list(map(int, input().split()))


# N = 5
# pairs = [[1,2], [3,4], [5,1]]

print(pairs)

class UnionFind:
    def __init__(self, N):
        self.r = [-1] * N

    def root(self, x):
        if self.r[x] < 0:
            return x
        self.r[x] = self.root(self.r[x])
        return self.r[x]


    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.r[x] > self.r[y]:
            x, y = y, x

        self.r[x] += self.r[y]
        self.r[y] = x
        return True

    def size(self, x):
        return -self.r[self.root(x)]

uf = UnionFind(N)
for pair in pairs:
    a = pair[0] - 1
    b = pair[1] - 1
    uf.unite(a, b)

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

print(ans)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

# n, m = map(int, input().split())
# 
# pairs = [0] * m
# for i in range(m):
#     pairs[i] = set(map(int, input().split()))


N = 5
pairs = [[1,2], [3,4], [5,1]]

print(pairs)

class UnionFind:
    def __init__(self, N):
        self.r = [-1] * N

    def root(self, x):
        if self.r[x] < 0:
            return x
        self.r[x] = self.root(self.r[x])
        return self.r[x]


    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.r[x] > self.r[y]:
            x, y = y, x

        self.r[x] += self.r[y]
        self.r[y] = x
        return True

    def size(self, x):
        return -self.r[self.root(x)]

uf = UnionFind(N)
for pair in pairs:
    a = pair[0] - 1
    b = pair[1] - 1
    uf.unite(a, b)

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

print(ans)

Submission status: Wrong Answer

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

setl = []
l = 0

for i in range(m):
    a, b = map(int, input().split())
    flag = False
    for j in range(l):
        if a in setl[j]:
            setl[j].add(b)
            flag = True
        elif b in setl[j]:
            setl[j].add(a)
            flag = True
        if flag:
            break
    if not flag:
        setl.append({a, b})
        l += 1

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
friend_list = []
friend_list2 = []
if m != 0:
  for i in range(m):
    a, b = map(int, input().split())
    friend_list.append([a, b])
while friend_list:
  friend = friend_list.pop()
  include_flag = False
  for i in friend_list2:
    if friend[0] in i and friend[1] not in i:
      i.append(friend[1])
      include_flag = True
      break
    elif friend[1] in i and friend[0] not in i:
      i.append(friend[0])
      include_flag = True
      break
  if not friend_list2 or not include_flag:
    friend_list2.append(friend)

if friend_list2:
  print(max(map(len, friend_list2)))
else:
  print(n)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
friend_list = []
friend_list2 = []
if m != 0:
  for i in range(m):
    a, b = map(int, input().split())
    friend_list.append([a, b])
while friend_list:
  friend = friend_list.pop()
  include_flag = False
  for i in friend_list2:
    if friend[0] in i and friend[1] not in i:
      i.append(friend[1])
      include_flag = True
      break
    elif friend[1] in i and friend[0] not in i:
      i.append(friend[0])
      include_flag = True
      break
  if not friend_list2 or not include_flag:
    friend_list2.append(friend)

if friend_list2:
  print(max(map(len, friend_list2)))
else:
  print(0)

Submission status: Wrong Answer

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

dic = dict()
dicSet = set()
dicList = dict()
count = 0
countList= set()

ans = 0

for i in range(m):
    a,b = list(map(int,input().split()))
    if not(a in dicSet) and not(b in dicSet):
        dic[count] = set()
        dic[count].add(a)
        dic[count].add(b)
        dicList[a] = count
        dicList[b] = count
        countList.add(count)
        count += 1
        dicSet.add(a)
        dicSet.add(b)

    elif a in dicSet and b in dicSet:
        if dicList[a] != dicList[b]:
            dic[count] = dic[dicList[a]] | dic[dicList[b]]
            countList.add(count)
            #del dic[dicList[a]]
            countList.discard(dicList[a])
            #del dic[dicList[b]]
            countList.discard(dicList[b])
            dicList[a] = count
            dicList[b] = count
            count += 1

    elif a in dicSet:
        dic[dicList[a]].add(b)
        dicList[b] = dicList[a]
        dicSet.add(b)
    else:
        dic[dicList[b]].add(a)
        dicList[a] = dicList[b]
        dicSet.add(a)


ans = 1

#print(dic)
#print(countList)

for i in countList:
    long = len(dic[i])
    if long > ans:
        ans = long

print(ans)

Submission status: Wrong Answer

Solution code:
#D
from queue import Queue

N,M=map(int,input().split())
Friend=[[] for i in range(N+1)]

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

Flag=[True for i in range(N+1)]
ans=0

for i in range(1,N+1):
    if Flag[i]:
        q=Queue()
        q.put(i)
        cnt=1
        while not q.empty():
            st=q.get()
            
            if not Flag[st]:
                continue

            Flag[st]=False
            for j in Friend[st]:
                if Flag[j]:
                    cnt+=1
                    Flag[j]=False
                    q.put(j)
        
        ans=max(ans,cnt)
print(ans)

Submission status: Wrong Answer

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

ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
 
friend_dict = defaultdict(list)
 
N, M = map(int, input().split())
 
for m in range(M):
  x, y = map(int, input().split())
  friend_dict[x].append(y)
  friend_dict[y].append(x)
  
for key,value in friend_dict.items():
  friend_dict[key] = set(value)
  
for key, value in friend_dict.items():
  for i in value:
    value_ = friend_dict[i]
    friend_dict[key] = value | value_

if M == 0:
  print(1)
else:
  max_num_group = max([len(set(v)) for v in friend_dict.values()])
  print(max_num_group)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

friend_dict = defaultdict(list)

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

for m in range(M):
  x, y = map(int, input().split())
  friend_dict[x].append(y)
  friend_dict[y].append(x)
  
if M == 0:
  print(1)
else:
  max_num_group = max([len(set(v)) for v in friend_dict.values()])
  print(max_num_group + 1)

Submission status: Wrong Answer

Solution code:

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

G = [ set() for row in range(N)]

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

ans = 0

for i in range(N):
    if len(G[i]) >= ans :
        ans = len(G[i])

print(ans+1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f  # 8bitごと
    x = x + (x >> 8)  # 16bitごと
    x = x + (x >> 16)  # 32bitごと
    x = x + (x >> 32)  # 64bitごと = 全部の合計
    return x & 0x0000007f


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

ans_list = []
for i in range(M):
    X, Y = map(int, input().split())
    X_bin = bin(1 << (X - 1))
    Y_bin = bin(1 << (Y - 1))
    com_bin = bin(int(X_bin, 2) | int(Y_bin, 2))

    flag = False
    for j in range(len(ans_list)):
        if bin((int(X_bin, 2) & int(ans_list[j], 2))) == X_bin or bin((int(Y_bin, 2) & int(ans_list[j], 2))) == Y_bin:
            ans_list[j] = bin(int(ans_list[j], 2) | int(com_bin, 2))
            flag = True

    if not flag:
        ans_list.append(com_bin)


max_count = 0
for j in range(len(ans_list)):
    count = popcount(int(ans_list[j], 2))
    if max_count < count:
        max_count = count

print(max_count)

Submission status: Wrong Answer

Solution code:
def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f  # 8bitごと
    x = x + (x >> 8)  # 16bitごと
    x = x + (x >> 16)  # 32bitごと
    x = x + (x >> 32)  # 64bitごと = 全部の合計
    return x & 0x0000007f


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

member = []

for i in range(N):
    member.append(i + 1)

ans_list = []
for i in range(M):
    X, Y = map(int, input().split())
    X_bin = bin(1 << (X - 1))
    Y_bin = bin(1 << (Y - 1))
    com_bin = bin(int(X_bin, 2) | int(Y_bin, 2))

    flag = False
    for j in range(len(ans_list)):
        if bin((int(X_bin, 2) & int(ans_list[j], 2))) == X_bin or bin((int(Y_bin, 2) & int(ans_list[j], 2))) == Y_bin:
            ans_list[j] = bin(int(ans_list[j], 2) | int(com_bin, 2))
            flag = True

    if not flag:
        ans_list.append(com_bin)


max_count = 0
for j in range(len(ans_list)):
    count = popcount(int(ans_list[j], 2))
    if max_count < count:
        max_count = count

print(max_count)

Submission status: Wrong Answer

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

G = []
if M != 0:
    for i, f in enumerate(F):
        new_grp = True
        for j, g in enumerate(G):
            if f[0] in g:
                if f[1] not in g:
                    G[j].append(f[1])
                new_grp = False
            if f[1] in g:
                if f[0] not in g:
                    G[j].append(f[0])
                new_grp = False
        if new_grp:
            G.append(f)
    print(max(map(len, G)))

else:
    print(N)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

t = [[] for _ in range(n+1)]

for a, b in ab:
    t[a].append(b)
    t[b].append(a)

ans = 1
frag = [True]*(n+1)

for i in range(1, n+1):
    if not frag[i]:
        continue
    d = deque(t[i])
    l = t[i]
    while d:
        num = d.popleft()
        if not frag[num]:
            continue
        for j in t[num]:
            l.append(j)
        frag[num] = False
    ans = max(ans, len(set(l)))

print(ans)

Submission status: Wrong Answer

Solution code:
import collections


n, m = map(int, input().split())
par = list(range(n))


def find(x):
    while par[x] != x:
        par[x] = par[par[x]]
        x = par[x]
    return x


def union(x, y):
    x1 = find(x)
    y1 = find(y)
    if x1 != y1:
        par[x1] = y1


for j in range(m):
    a, b = map(int, input().split())
    union(a - 1, b - 1)

counter = collections.Counter(par)
print(counter.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
def solve(N, M, fridens):
    union_find = [-1 for _ in range(N)]
    for A, B in friends:
        _merge(union_find, A, B)
    ans = len([x for x in union_find if x > -1])
    print(ans)


def _merge(union_find, A, B):
    union_find[B] = A


if __name__ == "__main__":
    N, M = map(int, input().split())
    friends = []
    for _ in range(M):
        friends.append([x - 1 for x in map(int, input().split())])
    solve(N, M, friends)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]

n,m = ip()
A = []
added = False
for i in range(m):
    x,y = ip()
    for s in A:
        if x in s or y in s:
            s.add(x)
            s.add(y)
            added = True
            break
    if not added:
        A.append({x,y})
    
ans = 0
for s in A:
    ans = max(ans, len(s))
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
d = {}
for _ in range(m):
    a,b = map(int,input().split())
    d[a] = d.get(a,[]) + [b]
    d[b] = d.get(b,[]) + [a]
ans = 2
visited = set()
for i in range(1,n+1):
    if i in visited: continue
    stack = [i]
    visited.add(i)
    cur = 1
    while stack:
        node = stack.pop()
        for nei in d.get(node,[]):
            if nei not in visited:
                stack.append(nei)
                visited.add(nei)
                cur += 1
    ans = max(ans,cur)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  n, m = map(int, input().split())
  friends = [set() for _ in range(n)]
  for i in range(m):
    a, b = map(int, input().split())
    friends[a-1].add(b-1)
    friends[b-1].add(a-1)
  ans = 1
  for i in range(1):
    temp = friends[i]
    for j in friends[i]:
      temp = temp|friends[j]
    ans = max(ans, len(temp))
  print(ans)
  
if __name__ == "__main__":
  main()