Problem p02573 (python)

Fixed submission:
#Uses python3
import sys
import threading

# This code is used to avoid stack overflow issues
sys.setrecursionlimit(10**7) # max depth of recursion
threading.stack_size(2**29)  # new thread will get stack of such size

visited = set()

def explore(adj, x, comp, cc):
    visited.add(x)
    if not(cc in comp):
        comp[cc] = []
    comp[cc].append(x)
    for w in adj[x]:
        if not (w in visited):
            explore(adj, w, comp, cc)

def number_of_components(adj, n):
    #visited = [False for _ in range(n)]
    cc = 0
    comp = dict()
    for v in range(n):
        if not(v in visited):
            explore(adj, v, comp, cc)
            cc += 1
    return comp


def main():
    n, m = map(int, input().split())
    adj = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        adj[a - 1].append(b - 1)
        adj[b - 1].append(a - 1)
    res = number_of_components(adj, n)
    max_ = 0
    for value in res.values():
        max_ = max(max_, len(value))
    print(max_)
    #print(n - number_of_components(adj, n) - 1)


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

Buggy submission (verdict: Runtime Error):
#Uses python3
import sys
import threading

# This code is used to avoid stack overflow issues
sys.setrecursionlimit(10**9) # max depth of recursion
threading.stack_size(2**32)  # new thread will get stack of such size

visited = set()

def explore(adj, x, comp, cc):
    visited.add(x)
    if not(cc in comp):
        comp[cc] = []
    comp[cc].append(x)
    for w in adj[x]:
        if not (w in visited):
            explore(adj, w, comp, cc)

def number_of_components(adj, n):
    #visited = [False for _ in range(n)]
    cc = 0
    comp = dict()
    for v in range(n):
        if not(v in visited):
            explore(adj, v, comp, cc)
            cc += 1
    return comp


def main():
    n, m = map(int, input().split())
    adj = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        adj[a - 1].append(b - 1)
        adj[b - 1].append(a - 1)
    res = number_of_components(adj, n)
    max_ = 0
    for value in res.values():
        max_ = max(max_, len(value))
    print(max_)
    #print(n - number_of_components(adj, n) - 1)


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

Buggy submission (verdict: Runtime Error):
#Uses python3
import sys
import threading

# This code is used to avoid stack overflow issues
sys.setrecursionlimit(10**6) # max depth of recursion
threading.stack_size(2**26)  # new thread will get stack of such size

visited = set()

def explore(adj, x, comp, cc):
    visited.add(x)
    if not(cc in comp):
        comp[cc] = []
    comp[cc].append(x)
    for w in adj[x]:
        if not (w in visited):
            explore(adj, w, comp, cc)

def number_of_components(adj, n):
    #visited = [False for _ in range(n)]
    cc = 0
    comp = dict()
    for v in range(n):
        if not(v in visited):
            explore(adj, v, comp, cc)
            cc += 1
    return comp


def main():
    n, m = map(int, input().split())
    adj = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        adj[a - 1].append(b - 1)
        adj[b - 1].append(a - 1)
    res = number_of_components(adj, n)
    max_ = 0
    for value in res.values():
        max_ = max(max_, len(value))
    print(max_)
    #print(n - number_of_components(adj, n) - 1)


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

Buggy submission (verdict: Runtime Error):
#Uses python3

import sys

visited = set()

def explore(adj, x, comp, cc):
    visited.add(x)
    if not(cc in comp):
        comp[cc] = []
    comp[cc].append(x)
    for w in adj[x]:
        if not (w in visited):
            explore(adj, w, comp, cc)

def number_of_components(adj, n):
    #visited = [False for _ in range(n)]
    cc = 0
    comp = dict()
    for v in range(n):
        if not(v in visited):
            explore(adj, v, comp, cc)
            cc += 1
    return comp

if __name__ == '__main__':
    input = sys.stdin.read()
    data = list(map(int, input.split()))
    n, m = data[0:2]
    data = data[2:]
    edges = list(zip(data[0:(2 * m):2], data[1:(2 * m):2]))
    adj = [[] for _ in range(n)]
    for (a, b) in edges:
        adj[a - 1].append(b - 1)
        adj[b - 1].append(a - 1)
    res = number_of_components(adj, n)
    max_ = 0
    for value in res.values():
        max_ = max(max_, len(value))
    print(max_)
    #print(n - number_of_components(adj, n) - 1)