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 Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int[] A = new int[M];
		int[] B = new int[M];

		for (int i = 0; i < M; i++) {
			A[i] = sc.nextInt()-1;
			B[i] = sc.nextInt()-1;
		}

		int counter=0;

		for (int i = 0; i < M; i++) {

			UnionFind uf=new UnionFind(N);

			for (int j = 0; j < M; j++) {

				if(i!=j) {
					uf.unite(A[j],B[j]);
				}

			}


			if(uf.getNumOfSet()>1) {
				counter++;
			}

		}

		pln(counter);




	}




	public class UnionFind {

		int[] par;
		int[] rank;
		String commentYes="Yes";
		String commentNO="No";

		public UnionFind(int MaxN,String yes,String no){
			par=new int[MaxN];
			rank=new int[MaxN];
			init(MaxN);

			commentYes=yes;
			commentNO=no;
		}

		public UnionFind(int MaxN){
			par=new int[MaxN];
			rank=new int[MaxN];
			init(MaxN);
		}

		void recieveEdges(int M,Scanner sc,int indexed) {

			int diff=0;

			if (indexed==0) {
				diff=1;
			}

			for (int i = 0; i < M; i++) {
				int A = sc.nextInt()-diff;
				int B = sc.nextInt()-diff;

				this.unite(A,B);
			}

		}


		//ｎ個の要素で初期化。
		void init(int n) {
			for(int i=0;i<n;i++) {
				par[i]=i;
				rank[i]=0;
			}
		}

		//木の根を求める
		public int root(int x) {

			//根までたどりついたので返させる。
			if(par[x]==x) {
				return x;
			}else {
				//経路圧縮
				return par[x]=root(par[x]);
			}

		}

		//xとyの根を比べて、同じ集合に属するかどうかを返す。
		public boolean same(int x,int y) {
			return root(x)==root(y);
		}

		//xとyの属する集合を併合
		public void unite(int x,int y) {
			x=root(x);
			y=root(y);

			if(x==y) {
				return;
			}

			if(rank[x]<rank[y]) {
				par[x]=y;
			}else {
				par[y]=x;

				if(rank[x]==rank[y]) {
					rank[x]++;
				}
			}
		}

		public void printJudge(int x,int y) {
			if(same(x,y)) {
				System.out.println(commentYes);
			}else {
				System.out.println(commentNO);
			}
		}

		//何本木があるか返させる。
		public int getNumOfSet() {
			Set<Integer>set=new TreeSet<Integer>();

			for(int i=0;i<par.length;i++) {
				set.add(this.root(i));
			}

			return set.size();
		}

		public void changeComennt(String yes,String no) {
			commentYes=yes;
			commentNO=no;
		}
	}


	//以下テンプレート

	public static int[] extgcd(int a,int b) {

		int x0=1;
		int x1=0;

		int y0=0;
		int y1=1;

		while(b != 0) {
			int q=a/b;
			int r=a%b;

			int x2=x0-q*x1;
			int y2=y0-q*y1;

			a=b;
			b=r;

			x0=x1;
			x1=x2;

			y0=y1;
			y1=y2;
		}

		return new int[] {a,x0,y0};

	}

	static int gcd(int a,int b) {

		if(b==0) return a;

		if(a<b) {
			int t=a;
			a=b;
			b=t;
		}

		return gcd(b,a%b);

	}

	static int lcm(int a,int b) {
		return a*b/gcd(a,b);
	}

	static void swap(int[] a) {
		int t;

		t=a[0];
		a[0]=a[1];
		a[1]=t;

		return;
	}
	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}