Problem p02573 (python)

Fixed submission:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline


class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))

    def find(self, a):
        acopy = a
        while a != self.parent[a]:
            a = self.parent[a]
        while acopy != a:
            self.parent[acopy], acopy = a, self.parent[acopy]
        return a

    def union(self, a, b):
        self.parent[self.find(b)] = self.find(a)




n , m = map(int , input().split())
#dic = defaultdict(set)
uf = UnionFind(n)
for ii in range(m):
	u,v = map(int , input().split())
	u-=1
	v-=1
	uf.union(u,v)
c = [0]*n
for i in range(n):
	c[uf.find(i)] += 1
print(max(c))



'''
import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)






########################################
def solve():
	n , m = map(int , input().split())
	dic = defaultdict(set)
	for ii in range(m):
		u,v = map(int , input().split())
		dic[u].add(v)
		dic[v].add(u)
	l = []
	visited = [0]*(n+2)
	def f(node):
		visited[node] = True
		temp = 0
		for nei in dic[node]:
			if not visited[nei]:
				temp += f(nei)
				#print("?",node, nei , temp)
		return temp
	for i in range(1,n+1):
		if not visited[i]:
			l.append(f(i)+1)
	#print(dic)
	#print(l)
	print(max(l))


threading.Thread(target=solve).start()

'''

Buggy submission (verdict: Runtime Error):
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline


import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)






########################################
def solve():
	n , m = map(int , input().split())
	dic = defaultdict(set)
	for ii in range(m):
		u,v = map(int , input().split())
		dic[u].add(v)
		dic[v].add(u)
	l = []
	visited = [0]*(n+1)
	def f(node):
		visited[node] = True
		if len(dic[node]) == 1:
			return 1
		temp = 1
		for nei in dic[node]:
			if not visited[nei]:
				temp += f(nei)
				#print("?",node, nei , temp)
		return temp
	for i in range(1,n+1):
		if not visited[i]:
			l.append(f(i))
	#print(dic)
	#print(l)
	print(max(l))


threading.Thread(target=solve).start()

Buggy submission (verdict: Runtime Error):
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################
n , m = map(int , input().split())
dic = defaultdict(set)
for ii in range(m):
	u,v = map(int , input().split())
	dic[u].add(v)
	dic[v].add(u)
l = []
visited = [0]*(n+1)
def f(node):
	visited[node] = True
	if len(dic[node]) == 1:
		return 1
	temp = 1
	for nei in dic[node]:
		if not visited[nei]:
			temp += f(nei)
			#print("?",node, nei , temp)
	return temp
for i in range(1,n+1):
	if not visited[i]:
		l.append(f(i))
#print(dic)
#print(l)
print(max(l))