Problem:
Score : 300 points

Problem Statement

You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.

The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i.

An edge whose removal disconnects the graph is called a bridge.

Find the number of the edges that are bridges among the M edges.

Notes

A self-loop is an edge i such that a_i=b_i (1 \leq i \leq M).

Double edges are a pair of edges i,j such that a_i=a_j and b_i=b_j (1 \leq i<j \leq M).

An undirected graph is said to be connected when there exists a path between every pair of vertices.

Constraints

2 \leq N \leq 50

N-1 \leq M \leq min(N(N−1)⁄2,50)

1 \leq a_i<b_i \leq N

The given graph does not contain self-loops and double edges.

The given graph is connected.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

Print the number of the edges that are bridges among the M edges.

Sample Input 1

7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7

Sample Output 1

4

The figure below shows the given graph:

The edges shown in red are bridges. There are four of them.

Sample Input 2

3 3
1 2
1 3
2 3

Sample Output 2

0

It is possible that there is no bridge.

Sample Input 3

6 5
1 2
2 3
3 4
4 5
5 6

Sample Output 3

5

It is possible that every edge is a bridge.

Solution in PyPy3 (2.4.0) (judge verdict: Accepted)

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)