Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10000000)
n , m = map(int,input().split())
g = [i for i in range(n)]
def find(x):
    if g[x] == x:
        return x
    g[x] = find(g[x])
    return g[x]
def union(x,y):
    x = find(x)
    y = find(y)
    if x!=y:
        g[x] = y

for i in range(m):
    xi,yi,zi = map(int,input().split())
    union(xi-1,yi-1)

print(len(set([find(i) for i in range(n)])))


Fixed submission:
import sys
sys.setrecursionlimit(100000)
n , m = map(int,input().split())
g = [i for i in range(n)]
def find(x):
    if g[x] == x:
        return x
    g[x] = find(g[x])
    return g[x]
def union(x,y):
    x = find(x)
    y = find(y)
    if x!=y:
        g[x] = y

for i in range(m):
    xi,yi,zi = map(int,input().split())
    union(xi-1,yi-1)

ans = 0
for i in range(n):
    if find(i) == i:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n , m = map(int,input().split())
g = [i for i in range(n)]
def find(x):
    if g[x] == x:
        return x
    g[x] = find(g[x])
    return g[x]
def union(x,y):
    x = find(x)
    y = find(y)
    if x!=y:
        g[x] = y

for i in range(m):
    xi,yi,zi = map(int,input().split())
    union(xi-1,yi-1)

print(len(set([find(i) for i in range(n)])))


Fixed submission:
import sys
sys.setrecursionlimit(100000)
n , m = map(int,input().split())
g = [i for i in range(n)]
def find(x):
    if g[x] == x:
        return x
    g[x] = find(g[x])
    return g[x]
def union(x,y):
    x = find(x)
    y = find(y)
    if x!=y:
        g[x] = y

for i in range(m):
    xi,yi,zi = map(int,input().split())
    union(xi-1,yi-1)

ans = 0
for i in range(n):
    if find(i) == i:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n , m = map(int,input().split())
d = {}

g = [i for i in range(n+1)]
def find(x):
    if g[x] == x:
        return x
    g[x] = find(g[x])
    return g[x]
def union(x,y):
    x = find(x)
    y = find(y)
    if x!=y:
        g[x] = y

for i in range(m):
    xi,yi,zi = map(int,input().split())
    union(xi,yi)

print(len(set([find(i) for i in range(1,n+1)])))


Fixed submission:
import sys
sys.setrecursionlimit(100000)
n , m = map(int,input().split())
g = [i for i in range(n)]
def find(x):
    if g[x] == x:
        return x
    g[x] = find(g[x])
    return g[x]
def union(x,y):
    x = find(x)
    y = find(y)
    if x!=y:
        g[x] = y

for i in range(m):
    xi,yi,zi = map(int,input().split())
    union(xi-1,yi-1)

ans = 0
for i in range(n):
    if find(i) == i:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n , m = map(int,input().split())
d = {}
for i in range(m):
    xi, yi, zi = map(int,input().split())
    if xi in d:
        d[xi] += [yi]
    else:
        d[xi] = [yi]
    if yi in d:
        d[yi] += [xi]
    else:
        d[yi] = [xi]

def f(x):
    global v
    v.remove(x)
    if x in d:
        for k in d[x]:
            if k in v:
                f(k)


v = [i+1 for i in range(n)]
count = 0
while len(v) > 0:
    f(v[0])
    count += 1
print(count)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
n , m = map(int,input().split())
g = [i for i in range(n)]
def find(x):
    if g[x] == x:
        return x
    g[x] = find(g[x])
    return g[x]
def union(x,y):
    x = find(x)
    y = find(y)
    if x!=y:
        g[x] = y

for i in range(m):
    xi,yi,zi = map(int,input().split())
    union(xi-1,yi-1)

ans = 0
for i in range(n):
    if find(i) == i:
        ans += 1
print(ans)