Problem p02573 (python)

Fixed submission:
import collections

def searchRoot(n):
    par = parList[n]
    if n == par:
        if len(q) > 0:
            rootIn(q,n)
        return n
    else:
        q.append(n)
        return(searchRoot(par))

def rootIn(q,root):
    while len(q) > 0:
        parList[q.popleft()] = root

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

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

for i in range(m):
    a,b = list(map(int,input().split()))
    aRoot = searchRoot(a)
    bRoot = searchRoot(b)
    if aRoot != bRoot:
        parList[max(aRoot,bRoot)] = min(aRoot,bRoot)
    
#print(parList)

ansDic = dict()
rootSet = set()
for i in range(1,n+1):
    root = searchRoot(i)
    if root in rootSet:
        ansDic[root] += 1
    else:
        rootSet.add(root)
        ansDic[root] = 1

ans = 1
for i in rootSet:
    if ansDic[i] > ans:
        ans = ansDic[i]

print(ans)

Buggy submission (verdict: Runtime Error):
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)

Buggy submission (verdict: Runtime Error):
n,m = list(map(int,input().split()))

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

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
        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]]
            del dic[dicList[a]]
            del dic[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)

for i in range(0,count):
    long = len(dic[i])
    if long > ans:
        ans = long

print(ans)