Company: LinkedIn_9Aug
Difficulty: medium
Hackerland Travel Cost Problem Description The country of Hackerland is represented as a graph with g_nodes cities, numbered from 1 to g_nodes . The cities are connected by g_edges bidirectional roads. The i -th road connects city g_from[i] to city g_to[i] , and travelling along it (in either direction) requires g_weight[i] units of fuel. Vehicles in Hackerland have an unlimited fuel capacity. The cost of one unit of fuel in city k is arr[k - 1] , and any amount of fuel can be purchased in any city the vehicle is in. Fuel that has been bought stays in the tank and can be used on any later road. Given two cities A and B , determine the minimum cost to travel from city A to city B . If travel between these cities is impossible, the answer is -1 . Complete the function getMinCost(g_nodes, g_from, g_to, g_weight, arr, A, B) , which returns the minimum cost as a 64-bit integer. Input Format Read from standard input. g_nodes g_edges g_from[0] g_to[0] g_weight[0] ... g_from[g_edges-1] g_to[g_