Uber Circular Shuttle Optimization
Uber has launched a new circular shuttle service that operates on a fixed route, starting and ending at the same location while collecting passengers from various designated stops.
The service area consists of n pickup locations, numbered from 0 to n-1. These locations are interconnected by roads, each with a uniform travel cost of 1 unit. The road network is defined by n-1 edges, where each edge [ai, bi] represents a bidirectional road connecting locations ai and bi. This configuration forms a connected tree structure of pickup locations.
Passenger demand is represented by an array of size n, where passengers[i] equals 1 if there's a passenger waiting at location i, and 0 otherwise.
The shuttle service operates as follows: The shuttle may begin its route at any pickup location. Two operations are available at each stop:
Objective: Determine the minimum total cost required to collect all waiting passengers and return the shuttle to its starting location.
Important Constraints:
Goal: Find the optimal starting location and route strategy that minimizes the total operational cost.
Note: If you pass a road 2 times, the cost to traverse that road becomes 2.
Complete the function minimumShuttleCost in the editor.
minimumShuttleCost has the following parameters:
int[] passengers: A 1D array of integers wherepassengers[i] = 1indicates a passenger at pickup pointi, andpassengers[i] = 0indicates no passenger.int[][] edges: A 2D array of integers whereedges[i] = [ai, bi]indicates a bidirectional road connectingaiandbi.
Returns
int: Minimum cost incurred to start at a pickup point and return to the same starting point after collecting all the passengers from the pickup points.
1Example 1
2Example 2
Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 3·10^4passengers.size()equalsn.0 ≤ passengers[i] ≤ 1edges.lengthequalsn-1.edges[i].lengthequals2.0 ≤ ai, bi < nai ≠ bi