#FW0000027. Chi phí vận chuyển thấp nhất (Minimum Transport Cost)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chi phí vận chuyển thấp nhất (Minimum Transport Cost)
Minimum Transport Cost
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A directed transport-cost matrix gives each road price, with for no road. Passing through an intermediate city incurs that city’s tax, but trip endpoints are not taxed. For a journey from to , add the road costs along its directed route and the taxes at every intermediate city, excluding both endpoints. Find the minimum total expense and output a corresponding route. When more than one route is optimal, any optimal route is valid. Every query has a reachable destination in this PHOJ edition.
Input
The first line contains the number of cities . The next lines each contain integers specifying the directed road-cost matrix; an entry of means that no direct road exists, while a nonnegative value is the direct cost.
The next line gives the taxes for intermediate cities . Finally, read the query count and the ordered pairs .
Output
For each query print exactly three lines: From s to t : with the requested endpoints; Path: s-->...-->t listing every visited city separated by -->; and Total cost : C, where includes all road costs and the intermediate-city taxes. Separate the outputs for consecutive queries by one blank line.
Subtasks
- Subtask 1 (40 points): ; ; ; ; ; every query is reachable.
- Subtask 2 (60 points): ; ; ; ; every query is reachable.
Examples
Input
3
0 2 20
-1 0 3
-1 -1 0
1 5 1
3
1 3
1 2
3 3
Output
From 1 to 3 :
Path: 1-->2-->3
Total cost : 10
From 1 to 2 :
Path: 1-->2
Total cost : 2
From 3 to 3 :
Path: 3
Total cost : 0
Explanation
The route costs including the intermediate tax. Going directly costs . There is no endpoint tax.