You are planning on looting a temple.
The temple has
rooms numbered from
to
, every pair of which is connected by a tunnel which takes
second to traverse.
Initially,
of the tunnels are blocked and cannot be used.
There is one treasure in each room, and you want to collect every treasure in the temple.
You start in room
, the entrance of the temple, and can only traverse the temple by walking through tunnels.
Since the treasures can be heavy, you can carry at most one at a time and must return to the entrance to store them after picking one up.
When you pick up the
treasure, it sets off some traps, increasing the amount of time it takes to walk through each tunnel by
seconds.
You would like to calculate the minimum amount of time it would take for you to collect every piece of treasure and return to the entrance.
Since the temple is quite old, the tunnels are not very sturdy and will slowly collapse over time.
You know that in the future,
of the tunnels will collapse.
You also know which tunnels will collapse and in what order.
However, you don't know when exactly you will arrive at the temple.
Therefore, you want to calculate for each
from
to
the minimum amount of time it would take for you to collect every treasure in the temple if you arrive right after the
collapse event.
You can assume that the events are spaced very far apart in time, and tunnels won't collapse while you are in the temple.
Constraints


No tunnel will have its two endpoints being the same.
No tunnel will be specified more than once in the input.
The data will guarantee that it is always possible to reach every room from the entrance.
Subtask 1 [15%]

Subtask 2 [20%]

Subtask 3 [25%]

Subtask 4 [40%]
No additional constraints.
Input Specification
The first line contains three integers,
,
, and
, the number of rooms, the number of initially blocked tunnels, and the number of events, respectively.
The next line contains
integers,
.
The next
lines each contain two distinct integers, the endpoints of one of the blocked tunnels.
The next
lines each contain two distinct integers, the endpoints of the tunnel which collapses in this event.
Output Specification
Output
integers on separate lines, the
of which is the amount of time it would take for you to collect every treasure if you arrived immediately after the
event.
Sample Input
Copy
4 2 1
1 2 3 4
1 4
1 3
3 4
Sample Output
Copy
52
Explanation for Sample
After the first tunnel collapses, one optimal solution is to do the following steps:
- Go through rooms
, which takes
seconds.
- Pick up the treasure in room
, which increases the amount of time it takes to go through a tunnel to
seconds.
- Go through rooms
, which takes
seconds.
- Put down the treasure you are carrying.
- Go through rooms
, which takes
seconds.
- Pick up the treasure in room
, which increases the amount of time it takes to go through a tunnel to
seconds.
- Go through rooms
, which takes
seconds.
- Put down the treasure you are carrying.
- Go through rooms
, which takes
seconds.
- Pick up the treasure in room
, which increases the amount of time it takes to go through a tunnel to
seconds.
- Go through rooms
, which takes
seconds.
- Put down the treasure you are carrying.
- Pick up the treasure in room
.
This takes a total of
seconds.
Comments