Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input=sys.stdin.readline
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        visited[i]=False
        for e in G[i]:
            if visited[e]:
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()

Fixed submission:
def main():
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(1000000000)
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        visited[i]=False
        for e in G[i]:
            if visited[e]:
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input=sys.stdin.readline
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        for e in G[i]:
            if visited[e]:
                visited[e]=False
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()

Fixed submission:
def main():
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(1000000000)
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        visited[i]=False
        for e in G[i]:
            if visited[e]:
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input=sys.stdin.readline
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for i in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        for e in G[i]:
            if visited[e]:
                visited[e]=False
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()

Fixed submission:
def main():
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(1000000000)
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        visited[i]=False
        for e in G[i]:
            if visited[e]:
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()