Problem p02536 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

from collections import defaultdict

n,m=map(int,input().split())
visited=[0]*n
d=defaultdict(list)
def dfs(n):
    visited[n]=1
    #print(visited)
    for i in d[n]:
        if visited[i]==0:
            dfs(i)

for i in range(m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    d[a].append(b)
    d[b].append(a)

r=-1
for i in range (n):
    if visited[i]==0:
        dfs(i)
        r+=1
print(r)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


n,m = (int(x) for x in input().split())
visited = [False for _ in xrange(n)]

graph = dict(((i,[]) for i in xrange(n)))

def dfs(node):
    if visited[node]:
        return None
    visited[node] = True
    for next_node in graph[node]:
        dfs(next_node)
    return None

for _ in xrange(m):
    u,v = (int(x) - 1 for x in input().split())
    graph[u].append(v)
    graph[v].append(u)
ans = -1
for i in xrange(n):
    if not visited[i]:
        dfs(i)
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

n,m=map(int,input().split())
visited=[0]*n
d=defaultdict(list)
def dfs(n):
    visited[n]=1
    #print(visited)
    for i in d[n]:
        if visited[i]==0:
            dfs(i)

for i in range (m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    d[a].append(b)
    d[b].append(a)

r=-1
for i in range (n):
    if visited[i]==0:
        dfs(i)
        r+=1
print(r)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

n, m=map(int,input().split())
visited=[False for _ in range(n)]
graph = defaultdict(list)


def dfs(node):
    visited[node]=1
    for next_node in graph[node]:
        if visited[next_node]==0:
            dfs(next_node)

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

ans = -1
for i in range(n):
    if not visited[i]:
        dfs(i)
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

n,m = (int(x) for x in input().split())
visited = [False for _ in range(n)]
graph = defaultdict(list)



for _ in range(m):
    u,v = (int(x)-1 for x in input().split())
    graph[u].append(v)
    graph[v].append(u)

def dfs(node):
    if not visited[node]:
        visited[node] = True
        for next_node in graph[node]:
            dfs(next_node)

ans = -1
for i in range(n):
    if not visited[i]:
        dfs(i)
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = (int(x) for x in input().split())
visited = [False for _ in range(n)]
graph = dict(((i,[]) for i in range(n)))

def dfs(node):
    if visited[node]:
        return None
    visited[node] = True
    for next_node in graph[node]:
        dfs(next_node)
    return None

for _ in range(m):
    u,v = (int(x) - 1 for x in input().split())
    graph[u].append(v)
    graph[v].append(u)
ans = -1
for i in range(n):
    if not visited[i]:
        dfs(i)
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')


n,m = (int(x) for x in input().split())
visited = [False for _ in xrange(n)]

graph = dict(((i,[]) for i in xrange(n)))

def dfs(node):
    if visited[node]:
        return None
    visited[node] = True
    for next_node in graph[node]:
        dfs(next_node)
    return None

for _ in xrange(m):
    u,v = (int(x) - 1 for x in input().split())
    graph[u].append(v)
    graph[v].append(u)
ans = -1
for i in xrange(n):
    if not visited[i]:
        dfs(i)
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')


n,m = (int(x) for x in input().split())
visited = [False for _ in xrange(n)]

graph = dict(((i,[]) for i in xrange(n)))

def dfs(node):
    # global visited
    if visited[node]:
        return
    visited[node] = True
    for next_node in graph[node]:
        dfs(next_node)

for i in xrange(n):
    graph[i] = []
for _ in xrange(m):
    u,v = (int(x) - 1 for x in input().split())
    graph[u].append(v)
    graph[v].append(u)
ans = -1
for i in xrange(n):
    if not visited[i]:
        dfs(i)
        ans += 1
print(ans)