Every lost battle weakens and dissolves an army. The immediate task is to rally, and in rallying to recover order, courage, and confidence.
- Carl von Clausewitz, On War, Book IV, Chapter 13
Sorry to greet you with such news as soon as you open the problem, but you have just lost an important battle. Only a fraction of the units you commanded have survived, and they are scattered, fleeing to save their own lives.
Unless you want your own life to become another price of defeat, you must rally the fleeing units and restore their formations to keep the front from collapsing.
To prevent enemy infiltration and further advances while holding key routes and positions, you must swiftly move the scattered units to designated assembly points in the rear and reserve units to important defensive positions. You want to minimize each unit's travel time so that you can regain control while giving the enemy as few opportunities as possible.
There are points in this area that can serve as departure points or destinations, numbered through . Every pair of distinct points is connected by a direct two-way road. The time needed to travel directly from point to point is
The first line contains integers , , and , separated by spaces.
Each of the next lines contains the departure point and destination , of a movement plan, separated by a space.
For each movement plan, print the minimum travel time on its own line, in the order the plans are given.
For the first plan in example 1, traveling directly from point to point takes units of time, which is minimal.
For the second plan in example 1, traveling directly from point to point takes units of time, which is minimal.
This is the original version of BCD 13 Ex.
If you have solved this problem, try BCD 13 Ex as well.
Here, is a nonnegative integer, and denotes the remainder when is divided by .
You may pass through other points along the way. The time needed to travel along a route is the sum of the travel times of its roads.
You wish to review movement plans for redeploying your units. Each plan gives a unit's current point and destination . For each plan, find the minimum time needed to travel from point to point .
For the first plan in example 2, traveling directly from point to point takes units of time. The route takes units of time, which is minimal.