#P5227. Graph Connectivity After Edge Removal

    ID: 18463 Type: Default 1000ms 256MiB

Graph Connectivity After Edge Removal

Graph Connectivity After Edge Removal

You are given an undirected connected graph and several small subsets of its edges. The graph is defined as connected if and only if for any two vertices there exists a path connecting them. For each subset, you are asked to determine whether the graph remains connected after removing the edges in that subset. Note that the queries are independent; i.e. the removals in one query do not affect the graph in another query.

Input Format:

  • The first line contains two integers n and m, the number of vertices and edges in the graph.
  • The following m lines each contain two integers u and v representing an edge between vertices u and v. The edges are 1-indexed in the order they are given.
  • The next line contains an integer Q, the number of queries.
  • Each of the following Q lines represents a query. A query begins with an integer k (the number of edges to remove) followed by k distinct integers which are the indices of the edges to remove.

Output Format:

  • For each query, output a single line containing "YES" if the graph remains connected after removal, otherwise output "NO".

Note: In your solution, if any formulas are used, they should be written in LaTeX format. For example, the connectivity condition can be expressed as: \( \forall u,v \in V, \exists \text{ a path } p: u \to v \).

inputFormat

The input begins with two integers \(n\) and \(m\), where \(n\) is the number of vertices and \(m\) is the number of edges in the graph.

Then follow \(m\) lines, each containing two integers \(u\) and \(v\) that represent an undirected edge between vertices \(u\) and \(v\). The edges are numbered from 1 to \(m\) in the given order.

The next line contains an integer \(Q\), the number of queries.

Each of the following \(Q\) lines starts with an integer \(k\) (the number of edges to be removed) followed by \(k\) distinct integers representing the indices of the edges to remove.

outputFormat

For each query, print a single line containing "YES" if the graph remains connected after the removal of the specified edges, otherwise print "NO".

sample

4 3
1 2
2 3
3 4
2
1 2
0
NO

YES

</p>