영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
시간 제한 1초 · 메모리 제한 512 MB
Problem
There are n cities in Byteland but no roads between them. However, each day, a new road will be built. There will be a total of m roads.
Your task is to process q queries of the form: "after how many days can we travel from city a to city b for the first time?"
Input
The first input line has three integers n, m and q: the number of cities, roads and queries. The cities are numbered 1,2,…,n.
After this, there are m lines that describe the roads in the order they are built. Each line has two integers a and b: there will be a road between cities a and b.
Finally, there are q lines that describe the queries. Each line has two integers a and b: we want to travel from city a to city b.
Output
For each query, print the number of days, or -1 if it is never possible.
Constraints
- 1 ≤ n, m, q ≤ 2 · 10^5
- 1 ≤ a,b ≤ n
예제
예제 1
5 4 3 1 2 2 3 1 3 2 5 1 3 3 4 3 5
2 -1 4