## BPC 1 S5 - Temple

View as PDF

Points: 25 (partial)
Time limit: 3.0s
Memory limit: 512M

Author:
Problem types

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.

#### 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

4 2 1
1 2 3 4
1 4
1 3
3 4

#### Sample Output

52

#### Explanation for Sample

After the first tunnel collapses, one optimal solution is to do the following steps:

1. Go through rooms , which takes seconds.
2. Pick up the treasure in room , which increases the amount of time it takes to go through a tunnel to seconds.
3. Go through rooms , which takes seconds.
4. Put down the treasure you are carrying.
5. Go through rooms , which takes seconds.
6. Pick up the treasure in room , which increases the amount of time it takes to go through a tunnel to seconds.
7. Go through rooms , which takes seconds.
8. Put down the treasure you are carrying.
9. Go through rooms , which takes seconds.
10. Pick up the treasure in room , which increases the amount of time it takes to go through a tunnel to seconds.
11. Go through rooms , which takes seconds.
12. Put down the treasure you are carrying.
13. Pick up the treasure in room .

This takes a total of seconds.