Interesting proteins
Limits: 2 sec., 512 MiB
Its a known fact that the most important component of human body, it is basically the building material of every cell in your body. They are usually divided into two groups: simple and complex. But few know that there is one more but not popular classification, that divides proteins into interesting and uninteresting one.
Proteins can be represented as a set of \(\mathbf{N}\) nodes, where \(\mathbf{M}\) pairs of nodes are connected with aminoacids. The proteins are always connected, that means there is at least one sequence of connections between any two distinct pairs of nodes.
A ring in a protein is a sequence of no less than 3 unique nodes, in which adjacent nodes connected with aminoacids and ends of the sequence connected too.
Protein is called interesting if any node lies lies on at most one ring. An example of interesing protein is shown in the picture below:
To help with better understanding of interesting proteins, you were asked to answer several queries – will the original protein be interesing after adding connection between \(u_i\) and \(v_i\).
Input
The first line of input contains two integers \(\mathbf{N}\) and \(\mathbf{M}\), where \(\mathbf{N}\) is the number of nodes in the protein and \(\mathbf{M}\) is the number of connections between nodes.
Next \(\mathbf{M}\) lines contains description of connections. \(i^{th}\) connections is represented by two distinct integers \(u_i\) and \(v_i\), which is nodes that it joins.
This is followed by line with a single integers \(\mathbf{Q}\), which is the number of queries.
Following \(\mathbf{Q}\) lines describe queries. Each query contains two integers \(a_j\) and \(b_j\) – nodes that need to be connected to obtain graph for \(j^{th}\) query.
It is guaranteed that input represents connected protein.
Output
For each query output "Yes", if, when adding an connection between nodes \(a_j\) and \(b_j\), the protein remains interesting, and "No" otherwise.
Constraints
\(3 \le \mathbf{N} \le 2 * 10^5\), \(N - 1 \le \mathbf{M} \le 2 * 10^5\), \(0 \le \mathbf{Q} \le 2 * 10^5\), \(1 \le a_j, b_j \le 2 * 10^5\), \(1 \le v_j, u_j \le 2 * 10^5\)
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 8 8 1 2 1 3 2 4 2 5 4 6 4 7 6 8 6 7 5 3 5 2 3 5 6 1 4 7 8 | Yes Yes No No No |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|