


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.
For each test case, print the number of beautiful vertices.
Print the output of each test case in a separate line.
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
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’)