Buggy python submission (verdict: Time Limit Exceeded):
import collections

def main():
    n,m = map(int,input().split())
    f = [False for _ in range(n)]
    a = [[] for _ in range(n)]
    res = 0

    for _ in range(m):
        x,y,z = map(int,input().split())
        a[x-1].append(y-1)
        a[y-1].append(x-1)

    for i in range(n):
        if not f[i]:
            res += 1
            q=collections.deque()
            q.append(i)
            while q:
                t = q.pop()
                f[t] = True
                for g in a[t]:
                    if not f[g]:
                        q.append(g)
    print(res)
main()


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,m = map(int,input().split())
    f = [False for _ in range(n)]
    a = [[] for _ in range(n)]
    res = 0

    for _ in range(m):
        x,y,z = map(int,input().split())
        a[x-1].append(y-1)
        a[y-1].append(x-1)

    for i in range(n):
        if not f[i]:
            res += 1
            q=[]
            q.append(i)
            while q:
                t = q.pop()
                f[t] = True
                for g in a[t]:
                    if not f[g]:
                        q.append(g)
    print(res)
main()


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0


for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        q=[]
        q.append(i)
        while q:
            t = q.pop()
            f[t] = True
            for g in a[t]:
                if not f[g]:
                    q.append(g)
print(res)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)
print(res)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

def main():
    res = 0
    for _ in range(m):
        x,y,z = map(int,input().split())
        a[x-1].append(y-1)
        a[y-1].append(x-1)
    for i in range(n):
        if not f[i]:
            res += 1
            dfs(i)
    print(res)

main()

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)
print(res)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)

print(res)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)
print(res)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    a[x].append(y)
    a[y].append(x)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)

print(res)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)
print(res)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    global f
    global a
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(0,n):
    if not f[i]:
        res += 1
        dfs(i)

print(res)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)
print(res)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n+1)]
for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

def dfs(i):
    global f
    global a
    f[i] = True
    for g in a[i]:
        if not f[g]:
            dfs(g)
res = 0
for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)

print(res)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)
print(res)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

def dfs(i):
    global f
    global a
    f[i] = True
    for g in a[i]:
        if not f[g]:
            dfs(g)
res = 0
for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)

print(res)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)
print(res)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lx = []
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

def dfs(i):
    f[i] = True
    for g in a[i]:
        if not f[g]:
            dfs(g)
res = 0
for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)

print(res)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
f = [False for _ in range(n)]
a = [[] for _ in range(n)]
res = 0

def dfs(k):
    f[k] = True
    for g in a[k]:
        if not f[g]:
            dfs(g)

for _ in range(m):
    x,y,z = map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

for i in range(n):
    if not f[i]:
        res += 1
        dfs(i)
print(res)