Problem p03805 (python)

Fixed submission:
N, M = map(int, input().split())

Map = [[] for _ in range(N)]
reached = [False]*N

for _ in range(M):
    aa, bb = map(int, input().split())
    Map[aa-1].append(bb-1)
    Map[bb-1].append(aa-1)

cnt = 0

def DFS(x):
    global cnt
    global reached

    reached[x] = True

    if all(reached):
        cnt += 1
        reached[x] = False

        return

    for i in Map[x]:
        if reached[i]:
            continue

        else:
            DFS(i)

    reached[x] = False


DFS(0)
print(cnt)

Buggy submission (verdict: Runtime Error):
# import sys
# sys.setrecursionlimit(10**9)

N, M = map(int, input().split())

Map = [[] for _ in range(M)]
reached = [False]*N

for _ in range(M):
    aa, bb = map(int, input().split())
    Map[aa-1].append(bb-1)
    Map[bb-1].append(aa-1)

cnt = 0

def DFS(x):
    global cnt
    global reached

    reached[x] = True

    if all(reached):
        cnt += 1
        reached[x] = False

        return

    for i in Map[x]:
        if reached[i]:
            continue

        else:
            DFS(i)

    reached[x] = False


DFS(0)
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

N, M = map(int, input().split())

Map = [[] for _ in range(M)]
reached = [False]*N

for _ in range(M):
    aa, bb = map(int, input().split())
    Map[aa-1].append(bb-1)
    Map[bb-1].append(aa-1)

cnt = 0

def DFS(x):
    global cnt
    global reached

    reached[x] = True

    if all(reached):
        cnt += 1
        reached[x] = False

        return

    for i in Map[x]:
        if reached[i]:
            continue

        else:
            DFS(i)

    reached[x] = False


DFS(0)
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**20)

N, M = map(int, input().split())

Map = [[] for _ in range(M)]
reached = [False]*N

for _ in range(M):
    aa, bb = map(int, input().split())
    Map[aa-1].append(bb-1)
    Map[bb-1].append(aa-1)

cnt = 0

def DFS(x):
    global cnt
    reached[x] = True

    if all(reached):
        cnt += 1

    for i in range(N):
        if reached[i]:
            continue

        if i in Map[x]:
            DFS(i)

    reached[x] = False
    return

DFS(0)
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

N, M = map(int, input().split())

Map = [[] for _ in range(M)]
reached = [False]*N

for _ in range(M):
    aa, bb = map(int, input().split())
    Map[aa-1].append(bb-1)
    Map[bb-1].append(aa-1)

cnt = 0

def DFS(x):
    global cnt
    reached[x] = True

    if all(reached):
        cnt += 1

    for i in range(N):
        if reached[i]:
            continue

        if i in Map[x]:
            DFS(i)

    reached[x] = False
    return

DFS(0)
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

N, M = map(int, input().split())

Map = [[] for _ in range(M)]
reached = [False]*N

for _ in range(M):
    aa, bb = map(int, input().split())
    Map[aa-1].append(bb-1)
    Map[bb-1].append(aa-1)

cnt = 0

def DFS(x, pre):
    global cnt
    reached[x] = True

    if all(reached):
        cnt += 1

    for i in range(N):
        if i==pre or reached[i]:
            continue

        if i in Map[x]:
            DFS(i, x)

    reached[x] = False

DFS(0,-1)
print(cnt)