P5227 [AHOI2013] Connected Graph

Description

Given an undirected connected graph and several small sets, each set contains some edges. For each set, you need to determine whether the graph remains connected after deleting the edges in this set. Queries for different sets are independent of each other. A graph is defined to be connected if and only if for any two vertices, there exists a path connecting them.

Input Format

The first line contains two integers $n,m$, representing the number of vertices and edges in the undirected graph. The next $m$ lines each contain two integers $u,v$, meaning this edge connects vertices $u,v$. The edge number of the line $i+1$ is $i$. It is guaranteed that there are no multiple edges or self-loops. The next line contains an integer $k$, denoting the number of sets. The next $k$ lines each describe a set. The first number in each line is $c$, the number of edges in the set, followed by $c$ numbers representing the edges in the set.

Output Format

For each set, output one line indicating whether the graph is connected after removing the edges in the set. If it is connected, output ``Connected``; otherwise, output ``Disconnected``.

Explanation/Hint

$1~\leq~n,k~\leq~10^5$,$1~\leq~m~\leq~2~\times~10^5$,$1~\leq~c~\leq~4$。 Translated by ChatGPT 5