Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def solve(n, m, AB):
    g = [[] for _ in range(n)]
    for a, b in AB:
        g[a - 1].append(b - 1)
        g[b - 1].append(a - 1)

    q = deque(maxlen=m)
    q.append((-1, 0, [0]))
    used = {(-1, 0)}
    ng_edges = set()
    while len(q) > 0:
        prev, node, route = q.pop()
        for to in g[node]:
            if prev == to:
                continue
            if (prev, to) in used:
                route = route + [to]
                i = len(route) - 1
                while route[i] != prev:
                    if route[i] < route[i - 1]:
                        ng_edges.add((route[i], route[i - 1]))
                    else:
                        ng_edges.add((route[i - 1], route[i]))
                    i -= 1
            else:
                q.append((node, to, route + [to]))
                used.add((node, to))

    return m - len(ng_edges)

_n, _m = map(int, input().split())
_AB = [map(int, input().split()) for _ in range(_m)]
print(solve(_n, _m, _AB))


Fixed submission:
from collections import deque

def solve(n, m, AB):
    g = [[] for _ in range(n)]
    for a, b in AB:
        g[a - 1].append(b - 1)
        g[b - 1].append(a - 1)

    count = 0
    for a, b in AB:
        q = deque(maxlen=m)
        q.append(0)
        used = {0}
        while len(q) > 0:
            node = q.popleft()
            for to in g[node]:
                if to in used \
                    or node == a - 1 and to == b - 1 \
                    or node == b - 1 and to == a - 1:
                    continue
                q.append(to)
                used.add(to)
        if len(used) < n:
            count += 1

    return count

_n, _m = map(int, input().split())
_AB = [list(map(int, input().split())) for _ in range(_m)]
print(solve(_n, _m, _AB))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def solve(n, m, AB):
    g = [[] for _ in range(n)]
    for a, b in AB:
        g[a - 1].append(b - 1)
        g[b - 1].append(a - 1)

    q = deque(maxlen=m)
    q.append((-1, 0, [0]))
    used = {(-1, 0)}
    ng_edges = set()
    while len(q) > 0:
        prev, node, route = q.pop()
        for to in g[node]:
            if prev == to:
                continue
            if (prev, to) in used:
                route = route + [to]
                i = len(route) - 1
                while route[i] != prev:
                    if route[i] < route[i - 1]:
                        ng_edges.add((route[i], route[i - 1]))
                    else:
                        ng_edges.add((route[i - 1], route[i]))
                    i -= 1
            else:
                q.append((node, to, route + [to]))
                used.add((node, to))

    return m - len(ng_edges)

_n, _m = map(int, input().split())
_AB = [map(int, input().split()) for _ in range(_m)]
print(solve(_n, _m, _AB))


Fixed submission:
from collections import deque

def solve(n, m, AB):
    g = [[] for _ in range(n)]
    for a, b in AB:
        g[a - 1].append(b - 1)
        g[b - 1].append(a - 1)

    count = 0
    for a, b in AB:
        q = deque(maxlen=m)
        q.append(0)
        used = {0}
        while len(q) > 0:
            node = q.popleft()
            for to in g[node]:
                if to in used \
                    or node == a - 1 and to == b - 1 \
                    or node == b - 1 and to == a - 1:
                    continue
                q.append(to)
                used.add(to)
        if len(used) < n:
            count += 1

    return count

_n, _m = map(int, input().split())
_AB = [list(map(int, input().split())) for _ in range(_m)]
print(solve(_n, _m, _AB))