Problem p02536 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

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

def unite(Data, a, b):
    a, b = find(Data, a), find(Data, b)
    if a == b:
        pass
    elif Data[a] < Data[b]:
        Data[a] = Data[a] + Data[b]
        Data[b] = a
    else:
        Data[b] = Data[b] + Data[a]
        Data[a] = b 

n, m = map(int, input().split())
UF = [-1 for i in range(n)]
for i in range(m):
    ai, bi = map(int, input().split())
    ai, bi = ai - 1, bi - 1
    unite(UF, ai, bi)

ans = 0
for i in range(n):
    if UF[i] < 0: ans += 1 
print(ans - 1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)

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

def unite(Data, a, b):
    a, b = find(Data, a), find(Data, b)
    if a != b:
        if Data[a] < Data[b]:
            Data[a] = Data[a] + Data[b]
            Data[b] = a
        else:
            Data[b] = Data[b] + Data[a]
            Data[a] = b 

n, m = map(int, input().split())
UF = [-1 for i in range(n)]
for i in range(m):
    ai, bi = map(int, input().split())
    ai, bi = ai - 1, bi - 1
    unite(UF, ai, bi)

ans = 0
for i in range(n):
    if UF[i] < 0: ans += 1 
print(ans - 1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)

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

def unite(Data, a, b):
    a, b = find(Data, a), find(Data, b)
    if a != b:
        if Data[a] > Data[b]:
            Data[a] = Data[a] + Data[b]
            Data[b] = a
        else:
            Data[b] = Data[b] + Data[a]
            Data[a] = b 

n, m = map(int, input().split())
UF = [-1 for i in range(n)]
for i in range(m):
    ai, bi = map(int, input().split())
    ai, bi = ai - 1, bi - 1
    unite(UF, ai, bi)

ans = 0
for i in range(n):
    if UF[i] < 0: ans += 1 
print(ans - 1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)

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

def unite(Data, a, b):
    a, b = find(Data, a), find(Data, b)
    if a != b:
        if Data[a] > Data[b]:
            Data[a] = Data[a] + Data[b]
            Data[b] = a
        else:
            Data[b] = Data[b] + Data[a]
            Data[a] = b 

n, m = map(int, input().split())
UF = [-1 for i in range(n)]
for i in range(m):
    ai, bi = map(int, input().split())
    unite(UF, ai, bi)

ans = 0
for i in range(n):
    if UF[i] < 0: ans += 1 
print(ans - 1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)

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

def unite(Tree, a, b):
    a, b = find(Tree, a), find(Tree, b)
    if a != b:
        if Tree[a] > Tree[b]:
            Tree[a] = Tree[a] + Tree[b]
            Tree[b] = a
        else:
            Tree[b] = Tree[b] + Tree[a]
            Tree[a] = b 

n, m = map(int, input().split())
UF = [-1 for i in range(n)]
for i in range(m):
    ai, bi = map(int, input().split())
    unite(UF, ai, bi)

ans = 0
for i in range(n):
    if UF[i] < 0: ans += 1 
print(ans - 1)

Buggy submission (verdict: Runtime Error):
def find(Tree, x):
    if Tree[x] < 0:
        return x
    else:
        Tree[x] = find(Tree, x)
        return Tree[x] 

def unite(Tree, a, b):
    a, b = find(Tree, a), find(Tree, b)
    if a != b:
        if Tree[a] > Tree[b]:
            Tree[a] = Tree[a] + Tree[b]
            Tree[b] = a
        else:
            Tree[b] = Tree[b] + Tree[a]
            Tree[a] = b 

n, m = map(int, input().split())
UF = [-1 for i in range(n)]
for i in range(m):
    ai, bi = map(int, input().split())
    unite(UF, ai, bi)

ans = 0
for i in range(n):
    if UF[i] < 0: ans += 1 
print(ans - 1)