Codeforces Round 809 (Div. 2)
E
Qpwoeirut and Vertices
Codeforces
2300
原题
← D2→
翻译中…

You are given a connected undirected graph with $n$ vertices and $m$ edges. Vertices of the graph are numbered by integers from $1$ to $n$ and edges of the graph are numbered by integers from $1$ to $m$.

翻译中…

Your task is to answer $q$ queries, each consisting of two integers $l$ and $r$. The answer to each query is the smallest non-negative integer $k$ such that the following condition holds:

翻译中…
  • For all pairs of integers $(a, b)$ such that $l\le a\le b\le r$, vertices $a$ and $b$ are reachable from one another using only the first $k$ edges (that is, edges $1, 2, \ldots, k$).
翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1\le t\le 1000$) — the number of test cases.

翻译中…

The first line of each test case contains three integers $n$, $m$, and $q$ ($2\le n\le 10^5$, $1\le m, q\le 2\cdot 10^5$) — the number of vertices, edges, and queries respectively.

翻译中…

Each of the next $m$ lines contains two integers $u_i$ and $v_i$ ($1\le u_i, v_i\le n$) — ends of the $i$-th edge.

翻译中…

It is guaranteed that the graph is connected and there are no multiple edges or self-loops.

翻译中…

Each of the next $q$ lines contains two integers $l$ and $r$ ($1\le l\le r\le n$) — descriptions of the queries.

翻译中…

It is guaranteed that that the sum of $n$ over all test cases does not exceed $10^5$, the sum of $m$ over all test cases does not exceed $2\cdot 10^5$, and the sum of $q$ over all test cases does not exceed $2\cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, print $q$ integers — the answers to the queries.

翻译中…

Note

翻译中…

image Graph from the first test case. The integer near the edge is its number.

翻译中…

In the first test case, the graph contains $2$ vertices and a single edge connecting vertices $1$ and $2$.

翻译中…

In the first query, $l=1$ and $r=1$. It is possible to reach any vertex from itself, so the answer to this query is $0$.

翻译中…

In the second query, $l=1$ and $r=2$. Vertices $1$ and $2$ are reachable from one another using only the first edge, through the path $1 \longleftrightarrow 2$. It is impossible to reach vertex $2$ from vertex $1$ using only the first $0$ edges. So, the answer to this query is $1$.

翻译中…

image Graph from the second test case. The integer near the edge is its number.

翻译中…

In the second test case, the graph contains $5$ vertices and $5$ edges.

翻译中…

In the first query, $l=1$ and $r=4$. It is enough to use the first $3$ edges to satisfy the condition from the statement:

翻译中…
  • Vertices $1$ and $2$ are reachable from one another through the path $1 \longleftrightarrow 2$ (edge $1$).
  • Vertices $1$ and $3$ are reachable from one another through the path $1 \longleftrightarrow 3$ (edge $2$).
  • Vertices $1$ and $4$ are reachable from one another through the path $1 \longleftrightarrow 2 \longleftrightarrow 4$ (edges $1$ and $3$).
  • Vertices $2$ and $3$ are reachable from one another through the path $2 \longleftrightarrow 1 \longleftrightarrow 3$ (edges $1$ and $2$).
  • Vertices $2$ and $4$ are reachable from one another through the path $2 \longleftrightarrow 4$ (edge $3$).
  • Vertices $3$ and $4$ are reachable from one another through the path $3 \longleftrightarrow 1 \longleftrightarrow 2 \longleftrightarrow 4$ (edges $2$, $1$, and $3$).
翻译中…

If we use less than $3$ of the first edges, then the condition won't be satisfied. For example, it is impossible to reach vertex $4$ from vertex $1$ using only the first $2$ edges. So, the answer to this query is $3$.

翻译中…

In the second query, $l=3$ and $r=4$. Vertices $3$ and $4$ are reachable from one another through the path $3 \longleftrightarrow 1 \longleftrightarrow 2 \longleftrightarrow 4$ (edges $2$, $1$, and $3$). If we use any fewer of the first edges, nodes $3$ and $4$ will not be reachable from one another.

翻译中…

样例

Input #1
3
2 1 2
1 2
1 1
1 2
5 5 5
1 2
1 3
2 4
3 4
3 5
1 4
3 4
2 2
2 5
3 5
3 2 1
1 3
2 3
1 3
Output #1
0 1
3 3 0 5 5
2
InputCopy OutputCopy
题目信息
题号
1706E
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
DFS 及类似
分治
并查集
贪心
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。