Problem p02573 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

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

root = [-1] * n

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

def unite(x,y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x

def size(x):
    x = r(x)
    return -root[x]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    unite(x,y)


print(-min(root))

Buggy submission (verdict: Runtime Error):
import copy
(N,M) = map(int,input().split())
l = []
if M == 0:
    print(1)

else:
    for i in range(M):
        l.append([int(x) for x in input().split()])

    mn = 0
    for i in range(M):
        for j in range(2):
            mn = max(mn,l[i][j])

    s = [0 for i in range(mn+100)]
    k = [0 for i in range(M)]
    cnt = 0
    for i in range(M):
        if s[l[i][0]-1] == 0 and s[l[i][1]-1] == 0:
            cnt += 1
            s[l[i][0]-1] = cnt
            s[l[i][1]-1] = cnt
            k[cnt-1] += 2
        elif s[l[i][0]-1] == 0 and s[l[i][1]-1] != 0:
            s[l[i][0]-1] = s[l[i][1]-1]
            k[s[l[i][1]-1]-1] += 1
        elif s[l[i][0]-1] != 0 and s[l[i][1]-1] == 0:
            s[l[i][1]-1] = s[l[i][0]-1]
            k[s[l[i][0]-1]-1] += 1
        elif s[l[i][0]-1] != s[l[i][1]-1]:
            t = copy.deepcopy(s)
            s = [t[l[i][1]-1] for x in t if x == t[l[i][0]-1]]
            k[t[l[i][1]-1]-1] += k[t[l[i][0]-1]-1]

    print(max(k))

Buggy submission (verdict: Runtime Error):
import copy
(N,M) = map(int,input().split())
l = []
if M == 0:
    print(1)

else:
    for i in range(M):
        l.append([int(x) for x in input().split()])

    mn = 0
    for i in range(M):
        for j in range(2):
            mn = max(mn,l[i][j])

    s = [0 for i in range(mn)]
    k = [0 for i in range(M)]
    cnt = 0
    for i in range(M):
        if s[l[i][0]-1] == 0 and s[l[i][1]-1] == 0:
            cnt += 1
            s[l[i][0]-1] = cnt
            s[l[i][1]-1] = cnt
            k[cnt-1] += 2
        elif s[l[i][0]-1] == 0 and s[l[i][1]-1] != 0:
            s[l[i][0]-1] = s[l[i][1]-1]
            k[s[l[i][1]-1]-1] += 1
        elif s[l[i][0]-1] != 0 and s[l[i][1]-1] == 0:
            s[l[i][1]-1] = s[l[i][0]-1]
            k[s[l[i][0]-1]-1] += 1
        else:
            t = copy.deepcopy(s)
            s = [t[l[i][1]-1] for x in t if x == t[l[i][0]-1]]
            k[t[l[i][1]-1]-1] += k[t[l[i][0]-1]-1]

    print(max(k))

Buggy submission (verdict: Runtime Error):
(N,M) = map(int,input().split())
l = []

for i in range(M):
    l.append([int(x) for x in input().split()])

mn = 0
for i in range(M):
    for j in range(2):
        mn = max(mn,l[i][j])

s = [0 for i in range(mn)]
k = [0 for i in range(M)]
cnt = 0
for i in range(M):
    if s[l[i][0]-1] == 0 and s[l[i][1]-1] == 0:
        cnt += 1
        s[l[i][0]-1] = cnt
        s[l[i][1]-1] = cnt
        k[cnt-1] += 2
    elif s[l[i][0]-1] == 0 and s[l[i][1]-1] != 0:
        s[l[i][0]-1] = s[l[i][1]-1]
        k[s[l[i][1]]-1] += 1
    elif s[l[i][0]-1] != 0 and s[l[i][1]-1] == 0:
        s[l[i][1]-1] = s[l[i][0]-1]
        k[s[l[i][0]]-1] += 1

print(max(k))