Problem p03805 (python)

Fixed submission:
import sys

n, m = map(int, input().split())

array = [[int(x) for x in input().split()] for x in range(m)]

if m == 0:
    print(0)
    sys.exit()

adj_array = [[] for x in range(n + 1)]
res_array = [True] + [False for x in range(n)]
for item in array:
    adj_array[item[0]].append(item[1])
    adj_array[item[1]].append(item[0])


def dfs(n, res_array, res):
    res_array[n] = True
    if False not in res_array:
        return res+1
    else:
        for next in adj_array[n]:
            if not res_array[next]:
                res = dfs(next, list(res_array), res)
    return res


res = 0
res_array[1] = True
print(dfs(1, res_array, res))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
array = [[int(x) for x in input().split()] for y in range(m)]
modify = [[] for x in range(m + 1)]

for value1, value2 in array:
    modify[value1].append(value2)
    modify[value2].append(value1)


def solver(start, array, visited, cnt):
    if visited[start]:
        return cnt
    else:
        visited[start] = True

    for i in array[start]:
        if len(set(visited)) == 1:
            return cnt+1
        else:
            cnt = solver(i, array, list(visited), cnt)

    return cnt



start = modify[1]
res = 0
for i in start:
    visited = [False if x != 0 and x != 1 else True for x in range(m + 1)]
    res += solver(i, modify, visited, 0)

print(res)

Buggy submission (verdict: Runtime Error):
import sys

n, m = map(int, input().split())

array = [[int(x) for x in input().split()] for x in range(m)]

if m == 0:
    print(0)
    sys.exit()

adj_array = [[] for x in range(m + 1)]
res_array = [True] + [False for x in range(n)]
for item in array:
    adj_array[item[0]].append(item[1])
    adj_array[item[1]].append(item[0])


def dfs(n, res_array, res):
    res_array[n] = True
    if False not in res_array:
        return res+1
    else:
        for next in adj_array[n]:
            if not res_array[next]:
                res = dfs(next, list(res_array), res)
    return res


res = 0
res_array[1] = True
print(dfs(1, res_array, res))

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

array = [[int(x) for x in input().split()] for x in range(m)]

adj_array = [[] for x in range(m + 1)]
res_array = [True] + [False for x in range(n)]
for item in array:
    adj_array[item[0]].append(item[1])
    adj_array[item[1]].append(item[0])


def dfs(n, res_array, res):
    res_array[n] = True
    if False not in res_array:
        return res+1
    else:
        for next in adj_array[n]:
            if not res_array[next]:
                res = dfs(next, list(res_array), res)
    return res


res = 0
res_array[1] = True
print(dfs(1, res_array, res))

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

array = [[int(x) for x in input().split()] for x in range(m)]

adj_array = [[] for x in range(m + 1)]
res_array = [True] + [False for x in range(m)]
for item in array:
    adj_array[item[0]].append(item[1])
    adj_array[item[1]].append(item[0])


def dfs(n, res_array, res):
    res_array[n] = True
    if False not in res_array:
        return res+1
    else:
        for next in adj_array[n]:
            if not res_array[next]:
                res = dfs(next, list(res_array), res)
    return res


res = 0
res_array[1] = True
print(dfs(1, res_array, res))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(50000)

n, m = map(int, input().split())

array = [[int(x) for x in input().split()] for x in range(m)]

if m == 0 or m == 1:
    print(1)
    sys.exit()

adjacency_list = [[] for x in range(n + 1)]

for i in array:
    adjacency_list[i[0]].append(i[1])
    adjacency_list[i[1]].append(i[0])

searched = [False for x in range(m+1)]


def calc(start, maze, searched):
    res = 0
    if searched[start]:
        return 0
    searched[start] = True

    if searched.count(True) == n:
        return 1
    else:
        for next in maze[start]:
            res += calc(next, maze, list(searched))
    return res


print(calc(1, adjacency_list, searched))

Buggy submission (verdict: Runtime Error):
import sys

n, m = map(int, input().split())

array = [[int(x) for x in input().split()] for x in range(m)]

if m == 0 or m == 1:
    print(1)
    sys.exit()

adjacency_list = [[] for x in range(n + 1)]

for i in array:
    adjacency_list[i[0]].append(i[1])
    adjacency_list[i[1]].append(i[0])

searched = [False for x in range(m+1)]


def calc(start, maze, searched):
    res = 0
    if searched[start]:
        return 0
    searched[start] = True

    if searched.count(True) == n:
        return 1
    else:
        for next in maze[start]:
            res += calc(next, maze, list(searched))
    return res


print(calc(1, adjacency_list, searched))

Buggy submission (verdict: Runtime Error):
import sys

n, m = map(int, input().split())

array = [[int(x) for x in input().split()] for x in range(m)]

if m == 0 or m == 1:
    print(1)
    sys.exit()

adjacency_list = [[] for x in range(m + 1)]

for i in array:
    adjacency_list[i[0]].append(i[1])
    adjacency_list[i[1]].append(i[0])

searched = [False for x in range(m+1)]


def calc(start, maze, searched):
    res = 0
    if searched[start]:
        return 0
    searched[start] = True

    if searched.count(True) == n:
        return 1
    else:
        for next in maze[start]:
            res += calc(next, maze, list(searched))
    return res


print(calc(1, adjacency_list, searched))

Buggy submission (verdict: Runtime Error):
import sys

n, m = map(int, input().split())
if m == 0:
    print(1)
    sys.exit()

array = [[int(x) for x in input().split()] for x in range(m)]

adjacency_list = [[] for x in range(m + 1)]

for i in array:
    adjacency_list[i[0]].append(i[1])
    adjacency_list[i[1]].append(i[0])

searched = [False for x in range(m+1)]


def calc(start, maze, searched):
    res = 0
    if searched[start]:
        return 0
    searched[start] = True

    if searched.count(True) == n:
        return 1
    else:
        for next in maze[start]:
            res += calc(next, maze, list(searched))
    return res


print(calc(1, adjacency_list, searched))

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(100000)


n, m = map(int, input().split())

array = [[int(x) for x in input().split()] for x in range(m)]

adjacency_list = [[] for x in range(m + 1)]

for i in array:
    adjacency_list[i[0]].append(i[1])
    adjacency_list[i[1]].append(i[0])

searched = [False for x in range(m+1)]


def calc(start, maze, searched):
    res = 0
    if searched[start]:
        return 0
    searched[start] = True

    if searched.count(True) == n:
        return 1
    else:
        for next in maze[start]:
            res += calc(next, maze, list(searched))
    return res


print(calc(1, adjacency_list, searched))

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

array = [[int(x) for x in input().split()] for x in range(m)]

adjacency_list = [[] for x in range(m + 1)]

for i in array:
    adjacency_list[i[0]].append(i[1])
    adjacency_list[i[1]].append(i[0])

searched = [False for x in range(m+1)]


def calc(start, maze, searched):
    res = 0
    if searched[start]:
        return 0
    searched[start] = True

    if searched.count(True) == n:
        return 1
    else:
        for next in maze[start]:
            res += calc(next, maze, list(searched))
    return res


print(calc(1, adjacency_list, searched))

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(1000000)


def judge(now, edges, searched):
    pattern = 0

    if searched[now] == "searched":
        return 0

    searched[now] = "searched"

    if searched.count("searched") == len(searched) - 1:
        return 1

    for next in edges[now]:
        pattern += judge(next, edges, list(searched))
    return pattern


def main():
    n, m = map(int, input().split())
    edges = [[int(x) for x in input().split()] for x in range(m)]
    adjacent_edges = [[] for x in range(m + 1)]
    for edge in edges:
        adjacent_edges[edge[0]].append(edge[1])
        adjacent_edges[edge[1]].append(edge[0])
    searched = ["yet" for x in range(n + 1)]

    print(judge(1, adjacent_edges, searched))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def judge(now, edges, searched):
    pattern = 0

    if searched[now] == "searched":
        return 0

    searched[now] = "searched"

    if searched.count("searched") == len(searched) - 1:
        return 1

    for next in edges[now]:
        pattern += judge(next, edges, list(searched))
    return pattern


def main():
    n, m = map(int, input().split())
    edges = [[int(x) for x in input().split()] for x in range(m)]
    adjacent_edges = [[] for x in range(m + 1)]
    for edge in edges:
        adjacent_edges[edge[0]].append(edge[1])
        adjacent_edges[edge[1]].append(edge[0])
    searched = ["yet" for x in range(n + 1)]

    print(judge(1, adjacent_edges, searched))


if __name__ == '__main__':
    main()