Rally in Deep Space
Time limit1sMemory limit1024 MB
For each query of two checkpoints, find the minimum sum of 2^k over the courses on a path, where k is the course's speed, modulo 10^9+7.
- Level
Medium7 of 10
- Topics
- Minimum spanning tree, Tree, Union-find, Graph
- Solved
- No attempts yet
문제
According to the Tsiolkovsky formula, accelerating a rocket from rest to speed takes this much fuel in total:
Here is the empty mass of the rocket and is the exhaust speed of the fuel. The formula holds only when the fuel tank is emptied during the acceleration.
In this problem, the fuel tank has unlimited capacity, , , , and . In this case, accelerating the rocket to speed takes units of fuel.
A rally is held in deep space. The course consists of checkpoints and two-way obstacle courses that connect the checkpoints. To pass obstacle course number , the rocket must be accelerated to speed .
To pass each checkpoint, the rocket must come to a complete stop. Braking uses no fuel. The fuel tank can be refilled at checkpoints.
Each pair of checkpoints is connected by at most one obstacle course. No obstacle course connects a checkpoint to itself. From any checkpoint, you can reach every other checkpoint by following obstacle courses.
The rally has stages. In each stage, the rocket must travel from checkpoint to checkpoint . Find the minimum fuel needed for each stage. Since fuel costs can be very large, print them modulo .
입력
The first line contains three space-separated integers: the number of checkpoints (), the number of obstacle courses (), and the number of stages ().
Each of the next lines contains two space-separated integers and (, ), meaning checkpoints and are connected by a two-way obstacle course. Line describes obstacle course .
Each of the next lines contains two space-separated integers and (, ), giving the checkpoints where the stage starts and ends.
출력
Print lines. On each line, print the minimum fuel needed for one stage. Print the answers in the same order as the stages appear in the input.