Chukjibeop
Time limit2sMemory limit1024 MB
Given M roads among N locations, find the minimum time from s to e for each query, where a 1-minute teleport may only reach locations not connected by roads.
Problem
A is troubled by severe traffic jams during the morning commute. A's area of activity has locations numbered through and two-way roads, each connecting two different locations. Crossing each road takes minute.
A, a skilled Taoist sorcerer, can use chukjibeop to move from any location to any other location in minute. However, teleporting from the current location to a location reachable by traveling along or more roads is considered cutting in line, which the sorcerers' code of ethics strictly prohibits.
Given pairs of start and destination, find the minimum time to travel from the start to the destination for each pair.
Input
The first line contains the number of locations , the number of roads , and the number of queries , separated by spaces. (; ; )
Each of the next lines contains two integers and , the endpoints of a road, separated by a space. () No two roads have the same pair of endpoints.
Each of the next lines contains a start and a destination , separated by a space. ()
Output
For each pair, print the minimum time to travel from the start to the destination on its own line, for lines in total.