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 C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, M) = Read2Longs();
            var a = new long[M];
            var b = new long[M];
            for (int i = 0; i < M; i++)
            {
                (a[i], b[i]) = Read2Longs();
                a[i]--; b[i]--;//インデックス変換
            }

            var count = 0;
            for (int i = 0; i < M; i++)
            {
                var uft = new UnionFindTree(N);
                for (int j = 0; j < M; j++)
                {
                    if (i == j) continue;
                    uft.Union(a[j], b[j]);
                }

                if (uft.GetSize(0) != N)
                {
                    count++;
                }
            }

            return count;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
    public class UnionFindTree
    {
        /// <summary>
        /// 親要素のインデックスを保持する
        /// 親要素が存在しない(自身がルートである)とき、マイナスでグループの要素数を持つ
        /// </summary>
        public long[] Parents { get; private set; }

        public UnionFindTree(long n)
        {
            Parents = new long[n];
            for (var i = 0; i < n; i++)
            {
                // 初期状態ではそれぞれが別のグループ(ルートは自分自身)
                // ルートなのでマイナスで要素数(1個)を保持する
                Parents[i] = -1;
            }
        }

        public bool Union(long x, long y)
        {
            var xRoot = Find(x);
            var yRoot = Find(y);

            // すでに同じグループの場合処理しない
            if (xRoot == yRoot) return false;

            // 要素数が少ないグループを多いほうに書き換えたい
            if (GetSize(xRoot) < GetSize(yRoot))
            {
                var tmp = xRoot;
                xRoot = yRoot;
                yRoot = tmp;
            }

            // まとめる先のグループの要素数を更新
            Parents[xRoot] += Parents[yRoot];

            // まとめられるグループのルートの親を書き換え
            Parents[yRoot] = xRoot;

            return true;
        }
        public bool IsUnited(long x, long y)
        {
            return Find(x) == Find(y);
        }
        public long Find(long x)
        {
            // 親がマイナスの場合は自分自身がルート
            if (Parents[x] < 0) return x;

            // ルートが見つかるまで再帰的に探す
            // 見つかったルートにつなぎかえる
            Parents[x] = Find(Parents[x]);

            return Parents[x];
        }
        public long GetSize(long x)
        {
            // ルート要素を取得して、サイズを取得して返す
            return -Parents[Find(x)];
        }
    }
}