Minimum Cost Path Through Two Errands

Company: Uber_1staug

Difficulty: medium

Problem Statement

Minimum Cost Path Through Two Errands Alex needs to run two errands before going to school, and they must be completed in a specific order. The city is an undirected weighted graph whose nodes are labeled 1 to g_nodes . Alex always starts at node 1 , and the school is always at node g_nodes . Road i joins nodes g_from[i] and g_to[i] and takes g_weight[i] minutes to travel in either direction. Alex must first pass through node x , then through node y , and finally arrive at node g_nodes . Any node and any road may be used as many times as needed, so the route does not have to be a simple path; it only has to reach x , then reach y after that, then end at g_nodes . Return the minimum total travel time of such a route, or -1 if no such route exists. (inferred -- the source does not say what to return when the graph is disconnected; -1 is what the original test data expects) Function Description Complete the function minCostPath : minCostPath(g_nodes, g_from, g_to, g_weight, x, y) g_nodes