#P8531. [Ynoi2003] 戌亥彗星
[Ynoi2003] 戌亥彗星
Problem Description
Define a graph as a “sea urchin” if it satisfies all of the following conditions:
- It is a connected graph.
- It contains exactly one simple cycle.
- For every vertex not on the cycle, its degree is at most .
There is a graph with vertices and edges. The -th edge connects and (the graph is not guaranteed to be connected).
Define the interval subgraph of a graph as , where , $V'=\{u_i\mid l\leq i\leq r\} \cup \{v_i\mid l\leq i\leq r\}$. That is, this interval subgraph contains exactly the edges in the interval and all vertices that appear in at least one edge in the interval.
Now there are queries. Each query gives an interval . For this , compute how many sub-intervals satisfy that the interval subgraph of the original graph is a sea urchin.
Additional notes for Condition 2:
- A simple cycle means: you can start from any vertex, traverse some non-repeated edges, and return to the start vertex; you must traverse at least one edge; and you do not visit any repeated vertex except that the start and end vertex are the same. For example, is a simple cycle. Two parallel edges also form a simple cycle. But a graph with only one vertex is not. Also, is not a simple cycle. (Here the cycle is written as a path starting from some vertex.)
- Condition also requires that, besides the cycle edges, there is no edge whose both endpoints are on this cycle.
Input Format
The first line contains an integer , meaning the number of vertices and the number of edges.
The next lines each contain two integers , describing an edge.
The next line contains an integer .
The next lines each contain two integers , describing a query.
Output Format
Output lines, each containing one number, the answer to the corresponding query.
10
1 3
3 4
1 2
5 2
5 6
2 6
3 4
2 9
2 1
3 1
5
1 10
9 10
3 10
1 7
4 9
4
0
3
3
1
Hint
Idea: lk&nzhtl1477, Solution: lk&ccz181078, Code: lk&ccz181078, Data: lk&ccz181078.
The testdata guarantees that there are no self-loops.
| Subtask ID | Special Property | Score | ||
|---|---|---|---|---|
| None | ||||
| The original graph is a sea urchin | ||||
| None | ||||
Translated by ChatGPT 5