This problem has a simple statement.
Given an undirected, unweighted graph of vertices and edges, and pairs of vertices, compute the distance between each pair of vertices.
We ran out of time trying to set strong test data for the problem though, so we did it randomly. Here's how we generated our test data.
- We picked values for , , and . The vertices are numbered from to .
- We generated, uniformly at random, a pair of distinct integers between and and added an edge between those vertices as long as they weren't already directly connected by an edge. This means the graph has no self-loops, nor parallel edges.
- The above step was repeated until the graph contains exactly edges.
- We generated, uniformly at random, pairs of integers between and for the queries.
Constraints
, , and .
Note: The sample does not respect the constraints. Your solution does not need to produce the correct output on the sample to get AC.
Input Specification
The first line of input contains three positive integers, , , and .
The next lines each contain two distinct positive integers from to , representing an edge between the two given vertices.
The next lines each contain two positive integers from to , representing a distance query between the two given vertices.
Output Specification
Output lines. For each distance query, output -1
if the two vertices are disconnected, otherwise output the distance between the two vertices.
Output answers for the queries in the order they're given, one query per line.
Sample Input
3 2 2
1 2
2 3
1 3
2 3
Sample Output
2
1
Comments
I literally just started c++. Is there something wrong with my program?? It says the compiler output is too long.
Your code does not compile. You should compile your code on your machine before submitting it - if the compiler output is too long, that usually means you have too many compiler errors. If your code does compile, it will automatically be run on the test cases.
If you can't compile locally for some reason, you can use a service like ideone.com. If you click on the link in the previous sentence, you can see the compiler errors for your program. You should fix the first errors before looking at the later ones.
thanks!