← 返回 microsoft 的题目列表Minimum Cost Travel with City-Specific Fuel Prices
类型:online_judge
Minimum Travel Cost with City-Specific Fuel Prices
Hackerland contains g_nodes cities numbered from 1 to g_nodes, connected by g_edges undirected roads.
The i-th road connects g_from[i] and g_to[i], and traveling through it consumes g_weight[i] units of fuel.
One unit of fuel costs arr[i] in city i.
The vehicle has unlimited fuel-tank capacity.
Any non-negative amount of fuel may be purchased in every city.
The vehicle starts with an empty tank.
Find the minimum cost to travel from city A to city B.
Return -1 if B is unreachable from A. Use a 64-bit integer for the answer because the total cost may exceed 32-bit range.
Function Signature
getMinCost(
int g_nodes,
int[] g_from,
int[] g_to,
int[] g_weight,
int[] arr,
int A,
int B
) -> long
Example
g_nodes = 5
g_from = [4, 5, 5, 1, 3, 4, 4]
g_to = [1, 3, 4, 5, 1, 2, 3]
g_weight = [1, 1, 8, 1, 3, 9, 5]
arr = [9, 11, 3, 2, 10]
A = 3
B = 2
Output:
27
One optimal route is 3 -> 5 -> 1 -> 4 -> 2.
Local Standard-Input Format
n m
u1 v1 w1
...
um vm wm
price1 price2 ... pricen
A B
The original prompt does not specify numerical limits. Use an adjacency list, a priority queue, and 64-bit arithmetic.
Example
Input
5 7
4 1 1
5 3 1
5 4 8
1 5 1
3 1 3
4 2 9
4 3 5
9 11 3 2 10
3 2
Output
27