TLE '16 Contest 6 (Mock CCC) S5 - Toll Routes

View as PDF

Submit solution


Points: 20 (partial)
Time limit: 2.0s
Java 5.0s
Python 8.0s
Memory limit: 512M

Author:
Problem type
Fax McClad flying over a toll route while towing a microwave to be delivered.

Fax McClad, Croneria's most profitable bounty hunter, has a part-time job delivering microwaves.

Croneria has N cities - numbered from 1 to N. M toll routes connect the cities. The ith toll route costs ti Cronerian Moneys to travel on and allows a one-way connection from city ui to city vi. An interesting thing to note about the Cronerian Toll Route system is that it is impossible to visit the same city twice on a single trip, even though all outgoing connections are usable.

However, the Committee for Charging Cronerians (CCC), the organization responsible for setting the tolls on the toll route system, is greedy. At times, they might decide to add an integer amount to the cost of every single toll route. In order to trick Cronerians into thinking they are fair, the CCC might add a negative amount to the costs.

D days will pass. On the jth day, Fax needs to deliver microwaves from city 1 to customers in city dj and the CCC adds cj moneys to the cost of every single toll route.

For each day, can you tell Fax the minimum amount of moneys he will need to spend to deliver the microwaves?

Input Specification

The first line of input will contain 3 space-separated integers, N (1N3000), M (1M6000), and D (1D2×106).

M lines of input follow. The ith line will contain 3 space-separated integers, ui, vi, and ti (1ui,viN;uivi;109ti109), specifying the ith toll route.

D lines of input follow. The jth line will contain 2 space-separated integers, cj and dj (1djN). The absolute value of the total change from any toll route's initial cost will not exceed 109.

For 1 of the 15 points, each city has at most 1 out-going toll route and D2×105.

For an additional 2 of the 15 points, N,M,D100 and the cost of any toll route will always be non-negative.

For an additional 2 of the 15 points, N,M,D30.

For an additional 2 of the 15 points, D1000.

Output Specification

For each day, print the minimum amount of moneys Fax needs to spend to reach his destination. If no path exists, print Cannot Deliver.

Sample Input

Copy
5 6 3
1 2 2
2 5 4
1 5 10
1 3 2
3 4 3
4 5 4
0 5
10 5
-20 5

Sample Output

Copy
6
20
-21

Explanation for Sample Output

On the first day, no changes were made to the toll routes, so Fax should take the path 125 for a minimal cost of 6.

On the second day, the cost of each toll route increased by 10, so Fax should take the path 15 for a minimal cost of 20.

On the third day, the cost of each toll route decreased by 20, so Fax should take the path 1345 for a minimal cost of 21.


Comments

There are no comments at the moment.