Under construction

Still being built. Things may change

Rally in Deep Space

Time limit1sMemory limit1024 MB

Summary
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 vv takes this much fuel in total:

m=m0(evu−1)m = m_0\left(e^{\frac{v}{u}} - 1\right)

Here m0m_0 is the empty mass of the rocket and uu 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, m0=1m_0 = 1, u=1u = 1, e≈2e \approx 2, and evu≫1e^{\frac{v}{u}} \gg 1. In this case, accelerating the rocket to speed vv takes 2v2^{v} units of fuel.

A rally is held in deep space. The course consists of VV checkpoints and EE two-way obstacle courses that connect the checkpoints. To pass obstacle course number kk, the rocket must be accelerated to speed kk.

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 QQ stages. In each stage, the rocket must travel from checkpoint pp to checkpoint qq. Find the minimum fuel needed for each stage. Since fuel costs can be very large, print them modulo 109+710^9 + 7.

입력

The first line contains three space-separated integers: the number of checkpoints VV (1≤V≤1051 \le V \le 10^5), the number of obstacle courses EE (1≤E≤3⋅1051 \le E \le 3 \cdot 10^5), and the number of stages QQ (1≤Q≤1051 \le Q \le 10^5).

Each of the next EE lines contains two space-separated integers aa and bb (1≤a≤V1 \le a \le V, 1≤b≤V1 \le b \le V), meaning checkpoints aa and bb are connected by a two-way obstacle course. Line k+1k + 1 describes obstacle course kk.

Each of the next QQ lines contains two space-separated integers pp and qq (1≤p≤V1 \le p \le V, 1≤q≤V1 \le q \le V), giving the checkpoints where the stage starts and ends.

출력

Print QQ 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.

Examples1

  1. Example 1

    Input
    4 6 3
    1 2
    3 2
    1 3
    4 1
    4 3
    2 4
    4 1
    1 3
    2 3
    
    Expected output
    16
    6
    4