Batyr I and Tima the Great - Ring Road Travel · IZhO 2024 #B
Physics · mechanics
Problem
There is a country that is a large ring road in the shape of a circle. On the ring road there are L cities evenly spaced at a distance 1 from each other. Neighboring cities on the ring road are connected by roads in the form of arcs. Unfortunately, the greedy King Batyr I has made these roads toll and charges 1 gold coin for travel. But Tima the Great made m illegal roads that connect two cities in a straight line (chord), i-th road connects two cities with numbers ai and bi.
Residents can now travel by using both toll roads and free roads. In doing so, residents can change direction at the intersections of the two roads Tima built as many times as they want, and it's still free!
You are given q queries, for the i-th query determine what is the minimum number of gold coins a resident needs to spend to travel from city xi to city yi.
Input:
The first line of input data contains three integers L,m,q(1≤L≤109,0≤m≤105,1≤q≤105) — the number of cities in the country, the number of illegal roads that Tima the Great built, and the number of queries.
The next m lines contain two integers each ai,bi(1≤ai<bi≤L) — the two cities that are connected by the i-th road.
The next q lines contain two integers each xi,yi(1≤xi,yi≤L) — two cities between which the resident has to travel.
Output:
Print q lines, in the i-th line print the minimum number of gold coins that must be paid to travel from city xi to city yi.