ZhenlongDai/ACPR huggingface dataset:
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def bfs(d,visit,i):
    q=[i]
    visit[i]=1
    count=1
    while(len(q)!=0):
        val=q.pop()
        for k in d[val]:
            if(visit[k]==0):
                count+=1
                visit[k]=1
                q.append(k)
    return count
    

n,m=map(int,input().split())
d=dict()
for i in range(1,n+1):
    d[i]=set()
for i in range(m):
    l,r=map(int,input().split())
    d[l].add(r)
    d[r].add(l)

visit=[0]*(n+1)

count=0
for i in range(1,n+1):
    if(visit[i]==0 and len(d[i])!=0):
        count=max(count,bfs(d,visit,i))
print(count)



Failing test case input:
1 0
1 1
1 2
0 6
-1 1
1 4
0 12
2 1
4 3
2 4
7 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
def bfs(d,visit,i):
    q=[i]
    visit[i]=1
    count=1
    while(len(q)!=0):
        val=q.pop()
        for k in d[val]:
            if(visit[k]==0):
                count+=1
                visit[k]=1
                q.append(k)
    return count
    

n,m=map(int,input().split())
d=dict()
for i in range(1,n+1):
    d[i]=set()
for i in range(m):
    l,r=map(int,input().split())
    d[l].add(r)
    d[r].add(l)

visit=[0]*(n+1)

count=0
for i in range(1,n+1):
    if(visit[i]==0 and len(d[i])!=0):
        count=max(count,bfs(d,visit,i))
if(count==0):
    print(1)
else:
    print(count)

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,Q = map(int,input().split())
par = [i for i in range(N+1)]
rank = [0]*(N+1)
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x]) 
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x]==rank[y]:rank[x]+=1

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

from collections import*
C=Counter(par)
print(max(C.values()))

Failing test case input:
5 3
1 2
3 4
3 1

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
N,Q = map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(Q)]
par = [i for i in range(N+1)]
rank = [0]*(N+1)
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x]) 
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x]==rank[y]:rank[x]+=1

for a,b in ab:
    unite(a,b)
for a,b in ab:
    unite(a,b)

from collections import*
C=Counter(par)
A=max(C.values())
print(A)
Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import deque
n,m=map(int,input().split())
d={}
ans=0
for i in range(m):
  a,b=map(int,input().split())
  if a in d:
    d[a].append(b)
    if b in d:
      d[a].extend(d[b])
  else:
    d[a]=deque([b])
  if b in d:
    d[b].append(a)
    if a in d:
      d[b].extend(d[a])
  else:
    d[b]=deque([a])
for i in d.values():
  ans=max(len(list(set(i))),ans)
print(ans)

Failing test case input:
1 0
1 1
1 2
0 6
-1 1
1 4
0 6
2 1
4 3
0 4
3 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import deque
n,m=map(int,input().split())
f=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  f[a].append(b)
  f[b].append(a)
q=deque()

for i in range(n):
  for j in f[i]:
    q.append(j)
  while q:
    p=q.popleft()
    if i!=p:
      f[i]+=f[p]
      for k in f[p]:
        q.append(k)
      f[p]=[]
ans=1
for i in f:
  cnt=len(list(set(i)))
  ans=max(cnt,ans)
print(ans)

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,M=map(int,input().split())
par=[i for i in range(N+1)]
size=[1 for i in range(N+1)]
def find(x):
    if x!=par[x]:
        par[x]=find(par[x])
    return par[x]
def union(x,y):
    if find(x)!=find(y):
        par[y] = par[x]
        size[x] += size[y]
res=N
for i in range(M):
    s,e=map(int,input().split())
    union(s,e)
c=0
for i in range(len(par)):
    if par[i]==i and size[i]!=1:

        c+=size[i]
print(c-1)

Failing test case input:
4 10
2 1
2 1
1 2
3 1
1 2
2 3
1 4
1 4
2 4
3 4

Expected output:
4


Actual output:
1


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
par=[i for i in range(N+1)]
size=[1 for i in range(N+1)]
def find(x):
    if x!=par[x]:
        par[x]=find(par[x])
    return par[x]
def union(x,y):
    if find(x)!=find(y):
        x, y = par[x], par[y]
        par[y] = par[x]
        size[x] += size[y]
res=N
for i in range(M):
    s,e=map(int,input().split())
    union(s,e)
print(max(size))
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

import sys
sys.setrecursionlimit(10**6)

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

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

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

Failing test case input:
5 2
1 4
3 4
3 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**6)

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

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

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

Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import defaultdict, deque
n, m = map(int, input().split())
g = defaultdict(set)

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


visited = [False]*n
ans = 0
for i in range(n):
    if not visited[i] and i in g:
        
        count = 1
        q = deque([i])
        visited[i] = 1
        while q:
            node = q.popleft()
            for nbr in g[node]:
                if not visited[nbr]:
                    q.append(nbr)
                    visited[nbr] = True
                    count += 1
            
        
        ans = max(ans, count)

print(ans)

Failing test case input:
2 0
1 1
2 1
1 6
2 0
1 2
1 3
1 4
4 3
2 4
4 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import defaultdict, deque
n, m = map(int, input().split())
g = defaultdict(set)

if m == 0:
    print(1)

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


    visited = [False]*n
    ans = 0
    for i in range(n):
        if not visited[i]:
            
            count = 1
            q = deque([i])
            visited[i] = 1
            while q:
                node = q.pop()
                for nbr in g[node]:
                    if not visited[nbr]:
                        q.append(nbr)
                        visited[nbr] = True
                        count += 1
                
            
            ans = max(ans, count)

    print(ans)
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = map(int, input().split())
path = [set() for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    path[a-1].add(b-1)
    path[b-1].add(a-1)
visited = [0] * N

ans = 1
for u in range(N):
    if visited[u] == 1:
        continue
    curr = 1
    next_u = path[u]
    while next_u:
        v = next_u.pop()
        if visited[v] == 1:
            continue
        visited[v] = 1
        curr += 1
        for w in path[v]:
            if visited[w] == 0:
                next_u.add(w)
    ans = max(ans, curr)

print(ans)

Failing test case input:
10 4
3 1
4 1
5 9
2 6

Expected output:
3

Actual output:
4


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
path = [set() for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    path[a-1].add(b-1)
    path[b-1].add(a-1)
visited = [0] * N

ans = 1
for u in range(N):
    if visited[u] == 1:
        continue
    curr = 1
    visited[u] = 1
    next_u = path[u]
    while next_u:
        v = next_u.pop()
        if visited[v] == 1:
            continue
        visited[v] = 1
        curr += 1
        for w in path[v]:
            if visited[w] == 0:
                next_u.add(w)
    ans = max(ans, curr)

print(ans)

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,m = map(int,input().split())
f = [[] for i in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    
    f[a].append(b)
    f[b].append(a)
    
import collections
q = collections.deque()

for i in range(n):
    for j in f[i]:
        q.append(j)
        
    while q:
        p = q.popleft()
        
        if p != i:
            f[i] += f[p]

            for k in f[p]:
                q.append(k)

            f[p] = []
        
    f[i] = sorted(set(f[i]))
            
ans = 0

for i in f:
    res = len(i)
    ans = max(ans,res)
    
print(ans)

Failing test case input:
2 0
1 1
2 1
1 6
2 1
1 2
1 3
1 4
3 3
2 4
4 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
f = [[] for i in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    
    f[a].append(b)
    f[b].append(a)
    
import collections
q = collections.deque()

for i in range(n):
    for j in f[i]:
        q.append(j)
        
    while q:
        p = q.popleft()
        
        if p != i:
            f[i] += f[p]

            for k in f[p]:
                q.append(k)

            f[p] = []
        
    f[i] = sorted(set(f[i]))
            
ans = 1

for i in f:
    res = len(i)
    ans = max(ans,res)
    
print(ans)
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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[c] = 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)

Failing test case input:
10 4
3 2
3 1
5 9
2 6

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
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())
    par_a, par_b = fp(a-1), fp(b-1)
    if par_a < par_b:
        Parent[par_b] = par_a
    else:
        Parent[par_a] = par_b

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)

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

maxi = 0
count = 1

countpar = [0 for i in range(n + 1)]
for i in range(1, n + 1):
  countpar[root(par[i])] += 1
print(max(countpar))


Failing test case input:
10 4
3 2
3 1
5 9
2 6

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
import resource

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

sys.setrecursionlimit(10 ** 6)
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)

maxi = 0
count = 1

countpar = [0 for i in range(n + 1)]

for i in range(1, n + 1):
  countpar[root(par[i])] += 1
print(max(countpar))
Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
l=lambda:map(int, input().split())
n,m=l()
p=[-1]*n
def r(x):
  while p[x]>=0: x=p[x]
  return x
def u(x,y):
  x,y=r(x),(y)
  if x==y: return
  if x>y: x,y=y,x
  p[x]+=p[y]
  p[y]=x
def e(x,y):
  return r(x)==r(y)
def s(x):
  return -p[r(x)]
for _ in range(m):
  a,b=l()
  u(a-1,b-1)
print(-min(p))


Failing test case input:
10 4
6 1
3 1
8 1
2 6

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
l=lambda:map(int, input().split())
n,m=l()
p=[-1]*n
def r(x):
  if p[x]<0:return x
  p[x]=r(p[x]);return r(p[x])
def u(x,y):
  x,y=r(x),r(y)
  if x==y: return  
  p[x]+=p[y]
  p[y]=x
def e(x,y):
  return r(x)==r(y)
def s(x):
  return -p[r(x)]
for _ in range(m):
  a,b=l()
  u(a-1,b-1)
print(-min(p))

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,m=map(int,input().split())

a=list(range(n))
def find(x):
  if a[x]==x:
    return x
  a[x] = find(a[x])
  return a[x]

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

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

Failing test case input:
10 4
6 1
3 1
8 1
2 6

Expected output:
5


Actual output:
2


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())

a=list(range(n))
def find(x):
  g = x
  while g != a[g]: g = a[g]
  a[x] = g
  return g

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

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

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

li = []
seen = [False]*n
for i in range(n):
    if seen[i]:
        continue
    q = deque([i])
    seen[i] = True
    cnt = 1
    while q:
        node = q.popleft()
        for i in graph[node]:
            if seen[i]:
                continue
            seen[i] = True
            cnt += 1
    li.append(cnt)
print(max(li))

Failing test case input:
10 4
6 1
3 1
5 9
2 6

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

li = []
seen = [False]*n
for i in range(n):
    if seen[i]:
        continue
    q = deque([i])
    seen[i] = True
    cnt = 1
    while q:
        node = q.popleft()
        for i in graph[node]:
            if seen[i]:
                continue
            seen[i] = True
            cnt += 1
            q.append(i)
    li.append(cnt)
print(max(li))
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


import collections

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

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

par = [i for i in range(n+1)]


def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x]) 
        return par[x]


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


def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x] = y


def size(x):
    return -par[find(x)]

for i in list:
    unite(i[0],i[1])

c = collections.Counter(par)

print(c.most_common()[0][1])

Failing test case input:
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 1
2 3
2 4
2 4

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):


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

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




def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True


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


def size(x):
    return -par[find(x)]



par = [-1]*n

for i in list:
  unite(i[0]-1, i[1]-1)

max = 0

for i in range(len(par)):
    if max<size(i):
        max = size(i)
print(max)

Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import collections as cc
I=lambda:list(map(int,input().split()))
mod=10**9+7
n,m=I()
g=[set() for i in range(n+1)]
ds=[i for i in range(n+1)]
def find(a):
    while ds[a]!=a:
        a=ds[a]
    return a
def join(a,b):
    x=find(a)
    y=find(b)
    if x!=y:
        ds[x]=ds[y]=min(x,y)
for i in range(m):
    x,y=I()
    g[x].add(y)
    g[y].add(x)
    join(x,y)
temp=cc.Counter(ds[1:])
print(max(temp.values()))

Failing test case input:
5 3
1 2
3 4
3 1

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
import collections as cc
I=lambda:list(map(int,input().split()))
mod=10**9+7
n,m=I()
ds=[i for i in range(n+1)]
r=[1]*(n+1)
def find(a):
    while ds[a]!=a:
        a=ds[a]
    return a
def join(a,b):
    x=find(a)
    y=find(b)
    if x!=y:
        ds[x]=ds[y]=min(x,y)
        r[min(x,y)]+=r[max(x,y)]
for i in range(m):
    x,y=I()
    join(x,y)
temp=cc.Counter(ds[1:])
print(max(r))
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,M = tuple(map(int,input().split()))
matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]

friendlist = [[i] for i in range(N)]

def match(ab):
    a,b=ab
    lsa = friendlist[a].copy()
    lsb = friendlist[b].copy()
    if a in lsb:
        return
    else:
        for ip in lsa:
            friendlist[ip].extend(lsb)
        for ip in lsb:
            friendlist[ip].extend(lsa)

for i in range(M):
    match(matchlist[i])
    print(friendlist)
print(max([len(item) for item in friendlist]))

Failing test case input:
10 4
6 1
3 1
5 9
2 6

Expected output:
4


Actual output:
[[0, 5], [1], [2], [3], [4], [5, 0], [6], [7], [8], [9]]
[[0, 5, 2], [1], [2, 0, 5], [3], [4], [5, 0, 2], [6], [7], [8], [9]]
[[0, 5, 2], [1], [2, 0, 5], [3], [4, 8], [5, 0, 2], [6], [7], [8, 4], [9]]
[[0, 5, 2, 1], [1, 5, 0, 2], [2, 0, 5, 1], [3], [4, 8], [5, 0, 2, 1], [6], [7], [8, 4], [9]]
4


Fixed submission (verdict: Accepted):
N,M = tuple(map(int,input().split()))


friendlist = list(range(N))

gplist = [[i] for i in range(N)]

def getgroup(a):
    A = friendlist[a]
    if A == a:
        return a
    else:
        return getgroup(A)

def match(ab):
    A = getgroup(ab[0])
    B = getgroup(ab[1])
    if A==B:
        return
    elif len(gplist[A])<len(gplist[B]):
        gplist[B].extend(gplist[A])
        friendlist[A] = B
    else:
        gplist[A].extend(gplist[B])
        friendlist[B] = A

for i in range(M):
    
    
    match(tuple(map(lambda x:int(x)-1,input().split())))




print(max([len(item) for item in gplist]))

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
n,m=map(int,input().split())
par=[i for i in range(n+1)]
rank=[0]*(n+1)
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 0
  if rank[x]<rank[y]:
    par[x]=y
  else:
    par[y]=x
    if rank[x]==rank[y]:
      rank[x]+=1
for i in range(m):
  a,b=map(int,input().split())
  unite(a,b)
counter=Counter(par)
print(counter.most_common()[0][1])

Failing test case input:
5 3
1 2
3 5
3 1

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
par=[i for i in range(n+1)]
size=[1]*(n+1)
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 0
  if size[x]<size[y]:
    size[y]+=size[x]
    par[x]=y
  else:
    size[x]+=size[y]
    par[y]=x
for i in range(m):
  a,b=map(int,input().split())
  unite(a,b)
print(max(size))
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, m = map(int, input().split())
groups = [[] for _ in range(n)]
count = 0

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

for i in range(n):
    a = groups[i]
    for j in set(groups[i]):
        a += groups[j-1]
    ans = max(len(set(a)), ans)
print(ans)
    


Failing test case input:
2 0
1 1
2 1
1 6
2 0
1 2
1 3
1 4
4 3
2 4
4 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
groups = [x for x in range(n)]
count = [0]*n

def UnionFind(x):
    a = x
    while a != groups[a]:
        a = groups[a]
    groups[x] = a
    return a

for _ in range(m):
    x, y = map(int, input().split())
    x, y = UnionFind(x-1), UnionFind(y-1)
    if x != y:
        groups[y] = x
    
for i in range(n):
    count[UnionFind(i)] += 1
print(max(count))

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,M = tuple(map(int,input().split()))
matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]

friendlist = list(range(N))

gplist = [[i] for i in range(N)]
def match(ab):
    a,b=ab
    gpa=friendlist[a]
    gpb=friendlist[b]
    mema=gplist[a].copy()
    memb=gplist[b].copy()
    if gpa==gpb:
        return
    else:
        gplist[gpa].extend(memb)
        for i in memb:
            friendlist[i]=gpa
        gplist[b] = [-1]


for i in range(M):
    match(matchlist[i])
    
    
print(max([len(item) for item in gplist]))

Failing test case input:
10 4
6 1
3 1
5 9
2 6

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
N,M = tuple(map(int,input().split()))


friendlist = list(range(N))

gplist = [[i] for i in range(N)]

def getgroup(a):
    A = friendlist[a]
    if A == a:
        return a
    else:
        return getgroup(A)

def match(ab):
    A = getgroup(ab[0])
    B = getgroup(ab[1])
    if A==B:
        return
    elif len(gplist[A])<len(gplist[B]):
        gplist[B].extend(gplist[A])
        friendlist[A] = B
    else:
        gplist[A].extend(gplist[B])
        friendlist[B] = A

for i in range(M):
    
    
    match(tuple(map(lambda x:int(x)-1,input().split())))




print(max([len(item) for item in gplist]))
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,m= map(int, input().split())
par = [i for i in range(n)]

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]

def unite(x, y):
  x = find(x)
  y = find(y)
  if x > y:
    par[x] = y
    find(x)
  else:
    par[y] = x
    find(y)

if m > 0:  
    for i in range(m):
        a, b = map(int, input().split())
        unite(a - 1, b - 1)

    print(par)
    ans=0
    for i in range(n):
        tmp = par.count(i)
        if tmp > ans:
            ans = tmp
    print(ans)

Failing test case input:
2 0
1 1
2 1
1 6
2 0
1 2
1 3
2 0
4 3
2 4
4 4

Expected output:
1


Actual output:

Fixed submission (verdict: Accepted):
n,m= map(int, input().split())
par = [i for i in range(n)]

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]

def unite(x, y):
  x = find(x)
  y = find(y)
  if x > y:
    par[x] = y
    find(x)
  else:
    par[y] = x
    find(y)

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

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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))))


Failing test case input:
10 4
6 1
3 1
5 6
2 6

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
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[ry] = 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))))
Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import Counter
N, M = map(int,input().split())
par = []
rank = [0] * (N + 1)
for i in range(N + 1): par.append(i)
def find(x):
    if par[x] == x: return x
    else:
         par[x] = find(par[x])
         return par[x]
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y: return 0
    if rank[x] < rank[y]: par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]: rank[x] += 1
def same(x,y):
    return find(x) == find(y)

for i in range(M):
    A, B = map(int,input().split())
    unite(A,B)
print(Counter(par).most_common()[0][1])


Failing test case input:
5 3
1 2
3 5
3 1

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
from collections import Counter
N, M = map(int,input().split())
par = []
rank = [0] * N
for i in range(N): par.append(i)
def find(x):
    if par[x] == x: return x
    else:
         par[x] = find(par[x])
         return par[x]
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y: return 0
    if rank[x] < rank[y]: par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]: rank[x] += 1

for i in range(M):
    A, B = map(int,input().split())
    A -= 1
    B -= 1
    unite(A,B)
for i in range(N):find(i)    
print(Counter(par).most_common()[0][1])

Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10 ** 9)
n, m = map(int, input().split())

friend = [set() for i in range(n)]

for i in range(m):
  a = list(map(int, input().split()))
  a.sort()
  x, y = a[0]-1,a[1]-1
  friend[x].add(y)

def dfs(s):
  if vis[s] == False:
    vis[s] = True
    ary.append(s)
    for i in friend[s]:
      dfs(i)
vis = [False for i in range(n)]
cnt = [0 for i in range(n)]
ans = 0
for i in range(n):
  cnt = 0
  ary = []
  dfs(i)
  ans = max(ans,len(ary))
print (ans)




Failing test case input:
5 2
1 4
3 4
5 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10 ** 9)
n, m = map(int, input().split())

friend = [set() for i in range(n)]

for i in range(m):
  a = list(map(int, input().split()))
  a.sort()
  x, y = a[0]-1,a[1]-1
  friend[x].add(y)
  friend[y].add(x)

def dfs(s):
  if vis[s] == False:
    vis[s] = True
    ary.append(s)
    for j in friend[s]:
      dfs(j)
vis = [False for i in range(n)]
ans = 0
for i in range(n):
  ary = []
  dfs(i)
  ans = max(ans,len(ary))
print (ans)
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = map(int, input().split())
path = [set() for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    path[a-1].add(b-1)
    path[b-1].add(a-1)
visited = [1] + [0] * (N-1)

ans = 1
for u in range(N):
    if visited[u] == 1:
        continue
    curr = 1
    next_u = path[u]
    while next_u:
        v = next_u.pop()
        if visited[v] == 1:
            continue
        visited[v] = 1
        curr += 1
        for w in path[v]:
            if visited[w] == 0:
                next_u.add(w)
    ans = max(ans, curr)

print(ans)

Failing test case input:
2 2
1 1
2 1
1 0
2 0
1 2
1 3
1 4
0 3
2 4
4 4

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
path = [set() for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    path[a-1].add(b-1)
    path[b-1].add(a-1)
visited = [0] * N

ans = 1
for u in range(N):
    if visited[u] == 1:
        continue
    curr = 1
    visited[u] = 1
    next_u = path[u]
    while next_u:
        v = next_u.pop()
        if visited[v] == 1:
            continue
        visited[v] = 1
        curr += 1
        for w in path[v]:
            if visited[w] == 0:
                next_u.add(w)
    ans = max(ans, curr)

print(ans)

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def resolve():
    from collections import defaultdict, deque
    N, M = [int(i) for i in input().split()]
    AABB = [[int(i) - 1 for i in input().split()] for _ in range(M)]
    dic = defaultdict(deque)
    for a, b in AABB:
        dic[a].append(b)
        dic[b].append(a)
    groups = [[] for _ in range(N)]
    cnt = 0
    for i in range(N):
        for j in range(N):
            if i not in groups[j] and all(a not in groups[j] for a in dic[i]):
                if len(groups[j]) == 0:
                    cnt += 1
                groups[j].extend(dic[i])
                break
    print(cnt)

resolve()


Failing test case input:
2 0
1 1
1 1
1 6
-1 1
1 2
1 3
2 0
4 3
2 4
4 0

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
def resolve():
    from collections import defaultdict, deque
    N, M = [int(i) for i in input().split()]
    AABB = [[int(i) - 1 for i in input().split()] for _ in range(M)]
    dic = defaultdict(set)
    for a, b in AABB:
        dic[a].add(b)
        dic[b].add(a)
    groups = [-1 for _ in range(N)]
    group = 0
    groupmemcnt = [0 for _ in range(N)]
    for i in range(N):
        if groups[i] != -1:
            continue
        groups[i] = group
        groupmemcnt[group] += 1
        que = deque(list(dic[i]))
        while len(que) > 0:
            j = que.popleft()
            if groups[j] != -1:
                continue
            groups[j] = group
            groupmemcnt[group] += 1
            que.extend(list(dic[j]))
        group += 1
    print(max(groupmemcnt))
    return

resolve()
Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
class union_find:
    def __init__(self, N):
        
        self.par = [-1 for i in range(N)]
    
    def root(self, i):
        if self.par[i] < 0:
            return i
        else:
            
            self.par[i] = self.root(self.par[i])
            return self.par[i]
    
    def same(self, a, b):
        return self.root(a) == self.root(b)
    
    def unite(self, a, b):
        if not self.same(a, b):
            self.par[a] = self.root(b)
            self.par[self.root(a)] -= 1

N, M = list(map(int, input().split()))
UF = union_find(N)
for _ in range(M):
    A, B = list(map(lambda x: int(x) - 1, input().split()))
    UF.unite(A, B)
print(-min(UF.par))

Failing test case input:
5 3
1 2
3 5
3 1

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
class union_find:
    def __init__(self, N):
        
        self.par = [-1 for i in range(N)]
    
    def root(self, i):
        if self.par[i] < 0:
            return i
        else:
            
            self.par[i] = self.root(self.par[i])
            return self.par[i]
    
    def same(self, a, b):
        return self.root(a) == self.root(b)
    
    def unite(self, a, b):
        if not self.same(a, b):
            self.par[self.root(a)] += self.par[self.root(b)]
            self.par[self.root(b)] = self.root(a)

N, M = list(map(int, input().split()))
UF = union_find(N)
for _ in range(M):
    A, B = list(map(lambda x: int(x) - 1, input().split()))
    UF.unite(A, B)
    
print(-min(UF.par))

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,M=map(int,input().split())
F = [set() for _ in range(N)]
for _ in range(M):
  a,b = map(lambda x: int(x)-1, input().split())
  F[a].add(b)
  F[b].add(a)

from collections import deque
 
def bfs():
  ans = 0
  done = set()
  for i in range(N):
    if i in done: continue
    queue = deque([i])
    num = 0
    while queue:
      p = queue.popleft()
      for p2 in F[p]:
        if p2 in done: continue
        done.add(p2)
        queue.append(p2)
        num += 1
    ans = max(ans,num)
  return ans
print(bfs())

Failing test case input:
2 0
1 1
1 2
0 6
-1 1
1 2
1 1
2 1
4 3
2 4
7 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
F = [set() for _ in range(N)]
for _ in range(M):
  a,b = map(lambda x: int(x)-1, input().split())
  F[a].add(b)
  F[b].add(a)

from collections import deque
 
def bfs():
  ans = 1
  done = set()
  for i in range(N):
    if i in done: continue
    queue = deque([i])
    num = 0
    while queue:
      p = queue.popleft()
      for p2 in F[p]:
        if p2 in done: continue
        done.add(p2)
        queue.append(p2)
        num += 1
    ans = max(ans,num)
  return ans
print(bfs())
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque
n,m = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(m):
  a,b = map(lambda z:int(z)-1,input().split())
  graph[a].append(b)
  graph[b].append(a)

size = [0 for i in range(n)]
for i in range(n):
  if not size[i]:
    tmp = 1
    stack = deque([i])
    while stack:
      now = stack.popleft()
      size[now] = tmp
      tmp+=1
      for to in graph[now]:
        if not size[to]:
          stack.append(to)

print(max(size))

Failing test case input:
4 10
2 1
2 1
1 2
3 1
1 2
2 3
1 4
1 4
2 4
3 4

Expected output:
4


Actual output:
16


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(m):
  a,b = map(lambda z:int(z)-1,input().split())
  graph[a].append(b)
  graph[b].append(a)

size = [0 for i in range(n)]
check = [True for i in range(n)]
for i in range(n):
  if check[i]:
    tmp = 1
    stack = [i]
    check[i] = False
    while stack:
      now = stack.pop()
      size[now] = tmp
      tmp+=1
      for to in graph[now]:
        if check[to]:
          check[to] = False
          stack.append(to)

print(max(size))

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = map(int, input().split())
connect = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  a, b = a - 1, b - 1
  connect[a].append(b)
  connect[b].append(a)  
  

ans = 0
used = [0] * N
for i in range(N):
  if used[i] == 0:
    used[i] = 1
    ans2 = 1
    queue = [i]
    while queue:
      now = queue.pop()
      for j in connect[i]:
        if used[j] == 0:
          used[j] = 1
          queue.append(j)
          ans2 += 1
  ans = max(ans, ans2)        
        
print(ans)


Failing test case input:
10 4
6 1
3 1
5 9
2 6

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
connect = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  a, b = a - 1, b - 1
  connect[a].append(b)
  connect[b].append(a)  
  

ans = 0
used = [0] * N
for i in range(N):
  if used[i] == 0:
    used[i] = 1
    ans2 = 1
    queue = [i]
    while queue:
      now = queue.pop()
      for j in connect[now]:
        if used[j] == 0:
          used[j] = 1
          queue.append(j)
          ans2 += 1
      
  ans = max(ans, ans2)        
        
print(ans)
Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import deque

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

grp = 0
color = ["white"] * (N + 1)
color[0] = "black"
for i in range(1, N + 1):
    if color[i] == "white":
        d = deque()
        d.append(i)
        a = []
        a.append(i)
        while (d):
            k = d.popleft()
            color[k] = "black"
            for j in rinsetu[k]:
                if color[j] == "white":
                    d.append(j)
                    a.append(j)
        grp=max(grp,len(a))
print(grp)

Failing test case input:
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
2 4

Expected output:
4


Actual output:
23


Fixed submission (verdict: Accepted):
from collections import deque

N, M = map(int, input().split())
rinsetu = [set() for _ in range(N + 1)]
for i in range(M):
    a, b = map(int, (input().split()))
    rinsetu[a].add(b)
    rinsetu[b].add(a)

grp = 0
color = ["white"] * (N + 1)
color_2 = ["white"] * (N + 1)
color[0] = "black"
for i in range(1, N + 1):
    count=1
    if color[i] == "white":
        d = deque()
        d.append(i)
        a = set()
        a.add(i)
        while (d):
            k = d.popleft()
            color[k] = "black"
            color_2[k]="black"
            for j in rinsetu[k]:
                if color[j] == "white" and color_2[j]=="white":
                    color_2[j]="black"
                    d.append(j)
                    count+=1
        grp=max(grp,count)
print(grp)

Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import defaultdict,deque
n,m = map(int,input().split())

d = defaultdict(list)

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

visited = [-1] + [False]*n
for i in range(m):
    a,b = map(int,input().split())
    d[a].append(b)
    d[b].append(a)
maxi = 1
for i in range(1,n+1):
    if visited[i]:
        continue
    cnt = 0
    que = deque([i])
    while que:
        v = que.pop()
        visited[v] = True
        cnt += 1
        for j in d[v]:
            if not visited[j]:
                que.append(j)
    maxi = max(maxi,cnt)
print(maxi)

Failing test case input:
4 10
2 1
2 1
1 2
2 1
1 2
1 3
1 4
1 4
2 4
3 4

Expected output:
4


Actual output:
11


Fixed submission (verdict: Accepted):
from collections import defaultdict,deque
n,m = map(int,input().split())

d = defaultdict(list)

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

visited = [-1] + [False]*n
for i in range(m):
    a,b = map(int,input().split())
    d[a].append(b)
    d[b].append(a)
maxi = 1
for i in range(1,n+1):
    if visited[i]:
        continue
    cnt = 0
    que = deque([i])
    while que:
        v = que.pop()
        if not visited[v]:
            visited[v] = True
            cnt += 1
        for j in d[v]:
            if not visited[j]:
                que.append(j)
    maxi = max(maxi,cnt)
print(maxi)
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
4 10
2 1
2 1
1 2
2 1
1 2
2 3
1 4
1 4
2 4
3 4

Expected output:
4


Actual output:
6


Fixed submission (verdict: Accepted):
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(friend)
                people_list.append(friend)
    if max_num < count:
        max_num = count
print(max_num)

Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n,m=map(int,input().split())
par = [-1]*(n+1)
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x]) 
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
      return 0
    else:
      if par[x] > par[y]:
        x,y = y,x
      par[x] += par[y]
      par[y] = x
def size(x):
    return -par[find(x)]

max_size=0
for _ in range(m):
  a,b=map(int,input().split())
  unite(a,b)
  max_size=max(size(b),max_size)

print(max_size)

Failing test case input:
2 0
1 1
1 2
0 6
-2 1
1 2
1 3
2 0
4 3
2 4
4 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
par = [-1]*(n+1)
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x]) 
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
      return 0
    else:
      if par[x] > par[y]:
        x,y = y,x
      par[x] += par[y]
      par[y] = x
def size(x):
    return -par[find(x)]

max_size=0
for _ in range(m):
  a,b=map(int,input().split())
  unite(a,b)
  
print(-min(par))
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

import sys
sys.setrecursionlimit(10**6)

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

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

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

Failing test case input:
2 0
1 1
1 2
0 6
-1 1
1 4
0 6
2 1
4 3
2 4
4 0

Expected output:
1


Actual output:
[[], [], []]
1


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**6)

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

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

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

Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

from collections import defaultdict, deque
n, m = map(int, input().split())
g = defaultdict(list)

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


visited = [False]*n
ans = 0
for i in range(n):
    if not visited[i] and i in g:
        
        count = 1
        q = deque([i])
        visited[i] = 1
        while q:
            node = q.pop()
            for nbr in g[node]:
                if not visited[nbr]:
                    q.append(nbr)
                    visited[nbr] = True
                    count += 1
            
        
        ans = max(ans, count)

print(ans)


Failing test case input:
2 0
1 1
1 2
0 6
-1 1
1 2
1 3
2 0
4 6
2 4
4 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import defaultdict, deque
n, m = map(int, input().split())
g = defaultdict(set)

if m == 0:
    print(1)

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


    visited = [False]*n
    ans = 0
    for i in range(n):
        if not visited[i]:
            
            count = 1
            q = deque([i])
            visited[i] = 1
            while q:
                node = q.pop()
                for nbr in g[node]:
                    if not visited[nbr]:
                        q.append(nbr)
                        visited[nbr] = True
                        count += 1
                
            
            ans = max(ans, count)

    print(ans)
Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import defaultdict, deque
n, m = map(int, input().split())
g = defaultdict(set)

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


visited = [False]*n
ans = 0
for i in range(n):
    if not visited[i] and i in g:
        
        count = 1
        q = deque([i])
        visited[i] = 1
        while q:
            node = q.pop()
            for nbr in g[node]:
                if not visited[nbr]:
                    q.append(nbr)
                    visited[nbr] = True
                    count += 1
            
        
        ans = max(ans, count)

print(ans)

Failing test case input:
1 0
1 1
1 2
0 6
-1 1
1 4
0 6
2 1
4 3
0 4
4 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import defaultdict, deque
n, m = map(int, input().split())
g = defaultdict(set)

if m == 0:
    print(1)

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


    visited = [False]*n
    ans = 0
    for i in range(n):
        if not visited[i]:
            
            count = 1
            q = deque([i])
            visited[i] = 1
            while q:
                node = q.pop()
                for nbr in g[node]:
                    if not visited[nbr]:
                        q.append(nbr)
                        visited[nbr] = True
                        count += 1
                
            
            ans = max(ans, count)

    print(ans)

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = map(int, input().split())

par = [i for i in range(N)]

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
    

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


Failing test case input:
5 3
1 2
3 5
3 1

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):

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

par = [i for i in range(N)]

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
    

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