← 返回 databricks 的题目列表Find Optimal Commute
类型:online_judge
Given a series of commute modes, compute the minimum cost/time from the start point to the destination for each mode. Assume the network structure of each mode is given, including start point, end point, and edge weights (representing time or cost). Requirements:
Use BFS for each mode to compute the minimum cost or time from the start to the destination.
Compare the results of different modes and find the optimal commute way.
No need to consider duplicate network structures.
Input
n denotes the number of different commute modes.
modes list, each mode contains a set of edges describing its network structure.
start denotes the starting point.
end denotes the destination.
Output
Return the minimum cost or time of the optimal commute mode.
Example Input
3
[[["A", "B", 10], ["B", "C", 20]], [["A", "C", 15]], [["A", "B", 5], ["B", "C", 5]]]
"A"
"C"
Example Output
15
Example
Input
3
[[["A", "B", 10], ["B", "C", 20]], [["A", "C", 15]], [["A", "B", 5], ["B", "C", 5]]]
"A"
"C"