CF1706E.Qpwoeirut and Vertices
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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≤a≤b≤r , vertices a and b are reachable from one another using only the first k edges (that is, edges 1,2,…,k ).
输入格式
The first line contains a single integer t ( 1≤t≤1000 ) — the number of test cases.
The first line of each test case contains three integers n , m , and q ( 2≤n≤105 , 1≤m,q≤2⋅105 ) — the number of vertices, edges, and queries respectively.
Each of the next m lines contains two integers ui and vi ( 1≤ui,vi≤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≤l≤r≤n ) — descriptions of the queries.
It is guaranteed that that the sum of n over all test cases does not exceed 105 , the sum of m over all test cases does not exceed 2⋅105 , and the sum of q over all test cases does not exceed 2⋅105 .
输出格式
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
说明/提示
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⟷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 .
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⟷2 (edge 1 ).
- Vertices 1 and 3 are reachable from one another through the path 1⟷3 (edge 2 ).
- Vertices 1 and 4 are reachable from one another through the path 1⟷2⟷4 (edges 1 and 3 ).
- Vertices 2 and 3 are reachable from one another through the path 2⟷1⟷3 (edges 1 and 2 ).
- Vertices 2 and 4 are reachable from one another through the path 2⟷4 (edge 3 ).
- Vertices 3 and 4 are reachable from one another through the path 3⟷1⟷2⟷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⟷1⟷2⟷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.