Problem p03575 (python)

Fixed submission:
import sys
import math
from fractions import gcd
from copy import deepcopy
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

class Node():
    def __init__(self, ch):
        self.ch_list = [ch]
        self.visited = False

N, M = map(int, sys.stdin.readline().split())
node_list = [0] * N

edge_list =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(M)]
for edge in edge_list:
    # リストのインデックスとnodeのidを統一しておく
    edge[0] -= 1
    edge[1] -= 1
for edge in edge_list:
    a, b = edge
    if node_list[a] == 0:
        node_list[a] = Node(b)
    else:
        if b not in node_list[a].ch_list:
            node_list[a].ch_list.append(b)

    if node_list[b] == 0:
        node_list[b] = Node(a)
    else:
        if a not in node_list[b].ch_list:
            node_list[b].ch_list.append(a)

def dfs(current_idx, ch_num, n_list):
    current = n_list[current_idx]
    if current == 0:
        return ch_num
    if current.visited:
        return ch_num
    ch_num += 1
    current.visited = True
    # print(current_idx + 1, list(map(lambda x: x + 1, current.ch_list)), ch_num)
    for idx in current.ch_list:
        # print("before", current_idx + 1, idx + 1, ch_num)
        ch_num = dfs(idx, ch_num, n_list)
        # print("after", current_idx + 1, idx + 1, ch_num)
    return ch_num

base_num = dfs(0, 0, deepcopy(node_list))

cnt = 0
for edge in edge_list:
    nl = deepcopy(node_list)
    a, b = edge
    nl[a].ch_list.remove((b))
    nl[b].ch_list.remove((a))
    num = dfs(0, 0, nl)
    # print(a + 1, b + 1, num)
    if num != base_num:
        cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
import math
from fractions import gcd
from copy import deepcopy
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  infile.readline().rstrip()
 =  list(infile.readline().rstrip())

## 数値
 =  int(infile.readline())
 =  map(int, infile.readline().split())
 =  list(map(int, infile.readline().split()))
 =  [list(map(int,list(infile.readline().split()))) for i in range(N)]
"""

class Node():
    def __init__(self, ch):
        self.ch_list = [ch]
        self.visited = False

infile = open("input.txt")
N, M = map(int, infile.readline().split())
node_list = [0] * N

edge_list =  [list(map(int,list(infile.readline().split()))) for i in range(M)]
for edge in edge_list:
    # リストのインデックスとnodeのidを統一しておく
    edge[0] -= 1
    edge[1] -= 1
for edge in edge_list:
    a, b = edge
    if node_list[a] == 0:
        node_list[a] = Node(b)
    else:
        if b not in node_list[a].ch_list:
            node_list[a].ch_list.append(b)

    if node_list[b] == 0:
        node_list[b] = Node(a)
    else:
        if a not in node_list[b].ch_list:
            node_list[b].ch_list.append(a)

def dfs(current_idx, ch_num, n_list):
    current = n_list[current_idx]
    if current == 0:
        return ch_num
    if current.visited:
        return ch_num
    ch_num += 1
    current.visited = True
    # print(current_idx + 1, list(map(lambda x: x + 1, current.ch_list)), ch_num)
    for idx in current.ch_list:
        # print("before", current_idx + 1, idx + 1, ch_num)
        ch_num = dfs(idx, ch_num, n_list)
        # print("after", current_idx + 1, idx + 1, ch_num)
    return ch_num

base_num = dfs(0, 0, deepcopy(node_list))

cnt = 0
for edge in edge_list:
    nl = deepcopy(node_list)
    a, b = edge
    nl[a].ch_list.remove((b))
    nl[b].ch_list.remove((a))
    num = dfs(0, 0, nl)
    # print(a + 1, b + 1, num)
    if num != base_num:
        cnt += 1

print(cnt)