You are given an undirected graph containing ‘N’ vertices that are connected by ‘M’ edges. Your task is to find the number of beautiful vertices. A vertex is beautiful if removing it will disconnect the graph, i.e., increase the number of connected components.
For Example:
You are given ‘N’ = 5, ‘M’ = 5 and ‘EDGES’ = [[1, 2], [1, 3], [3, 4], [3, 5], [4, 5]].

The beautiful vertices in the given graph are ‘1’ and ‘3’. If we remove ‘1’, vertex ‘2’ will be disconnected from the connected component (‘3’↔’4’↔’5’). If we remove vertex ‘3’, we will get two disjoint connected components (‘1’↔’2’) and (‘4’↔’5’).
The first line of the input contains a single integer 'T', representing the number of test cases.
The first line of each test case contains two space-separated integers, ‘N’ and ‘M’, representing the numbers of vertices and edges, respectively.
The next line ‘M’ lines contain two space-separated integers representing an edge.
Output Format:
For each test case, print the number of beautiful vertices.
Print the output of each test case in a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 2000
1 <= M <= N*(N-1)/2
1 <= EDGES[i][0] <= N
1 <= EDGES[i][1] <= N
Time Limit: 1 sec
2
5 5
1 2
1 3
3 4
3 5
4 5
3 2
1 2
2 3
2
1
For the first test case, the graph will look like this:

The beautiful vertices in the given graph are ‘1’ and ‘3’. If we remove ‘1’, vertex ‘2’ will be disconnected from the connected component (‘3’↔’4’↔’5’). If we remove vertex ‘3’, we will get two connected components (‘1’↔’2’) and (‘4’↔’5’).
For the second test case, the graph will look like this:

The beautiful vertex in the given graph is ‘2’. If we remove vertex ‘2’, we will get two disjoint components (‘1’) and (‘3’).
2
3 3
1 2
1 3
2 3
4 3
1 2
2 3
3 4
0
2
Try to use Depth-First Search.
In this approach, we will run a depth-first search from the starting node and keep track of the following information:
Note: DFS tree is the pattern we get when we perform a depth-search search on the graph.
Now, a vertex is a beautiful vertex if any of the following conditions is true:
Arrays/Lists used:
Algorithm :
Maintain a function DFS(int ‘NODE’, int ‘PARENT’, list<list> ‘ADJ’, int[] ‘LOW’, int[] ‘TIN’, boolean[] ‘VIS’, list ‘ANS’)
O(N + M), where ‘N’ is the number of vertices, and 'M' is the number of edges.
We are just performing DFS with additional arrays and the time complexity of DFS is O(N + M). Hence, the total time complexity is O(N + M).
O(N + M), where ‘N’ is the number of vertices, and 'M' is the number of edges.
The maximum space is taken by the adjacency list ‘ADJ’, i.e., O(N + M). Hence, the total space complexity is O(N + M).