题库练习 Qpwoeirut and Vertices
← 上一题 下一题 →

A15192 | Qpwoeirut and Vertices

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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$ ).

输入格式

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$ .

输出格式

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

输入输出样例

输入 #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
输出 #1
0 1 
3 3 0 5 5 
2
C++ 编辑器
输入
输出