


A connected component in the map is the maximum subset of cities that are connected i.e we can go from one city to any other in that subset.
The first line of input contains an integer ‘T’, which denotes the number of test cases. Then each test case follows.
The first line of each test case contains two separated integers ‘N’ and ‘M’ denoting ‘N’ cities and ‘M’ bridges.
Each of the next ‘M’ lines contains 2 integers ‘A’ and ‘B’, meaning that there is an edge between city A and city B.
The next line contains a single integer ‘Q’ denoting the number of queries
The next line contains ‘Q’ space-separated integers denoting the value of the nodes to be deleted.
For each query, if deleting the city on the map results in more number of connected components then print ‘Yes’, else print ‘No’.
Output for each query will be printed separated by a single space.
1 <= T <= 5
1 <= N <= 10^5
1 <= M <= 10^5
0 <= A <= N
1 <= B <= N
1 <= X <= N
Time Limit : 1 sec.
The idea is to find the articulation nodes in the graph. The articulation node is the node if removing it along with the edges will disconnect the graph.
For eg.
In the above figure, nodes with values 2 and 3 are Articulation nodes. As removing them along with edges will disconnect the graph.
After removing the node with value 2, the graph will look like
After removing the node with value 3, the graph will look like
The idea is to use DFS (Depth First Search). In DFS, we follow vertices in tree form called DFS tree. In the DFS tree, a vertex ‘u’ is the parent of another vertex ‘v’, if ‘v’ is discovered by ‘u’. In a DFS tree, a vertex ‘u’ is an articulation point if one of the following two conditions is true.
1) ‘u’ is the root of the DFS tree and it has at least two children.
2) ‘u’ is not the root of the DFS tree and it has a child ‘v’ such that no vertex in the subtree rooted with ‘v’ has a back edge to one of the ancestors (in DFS tree) of ‘u’.
We do a DFS traversal of a given graph to find out Articulation Points. In DFS traversal, we maintain a parent[] array where parent[u] stores the parent of the vertex ‘u’. For every vertex, count children. If the currently visited vertex ‘u’ is root (parent[u] is -1) and has more than two children, then store it in an unordered_set.
For the second case. We maintain an array discovery[] to store the discovery time of vertices. For every node ‘u’, we need to find out the earliest visited vertex (the vertex with minimum discovery time) that can be reached from the subtree rooted with ‘u’. So we maintain an additional array low[] for that.