For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
You are given connections, where each connections[i] = [city1, city2, cost] represents the cost to connect city1 and city2 together. (A connection is bidirectional: connecting city1 and city2 is the same as connecting city2 and city1.)
Return the minimum cost of connecting two given cities. The cost is the sum of the connection costs used. If the task is impossible, return -1.
Example:
Input: N = 3, connections = [[1,2,1],[1,3,6],[2,3,1]], u = 1, = 3
Output: 2
Explanation: the connection path is 1 -> 2 -> 3.
You are given connections, where each connections[i] = [city1, city2, cost] represents the cost to connect city1 and city2 together. (A connection is bidirectional: connecting city1 and city2 is the same as connecting city2 and city1.)
Return the minimum cost of connecting two given cities. The cost is the sum of the connection costs used. If the task is impossible, return -1.
Example:
Input: N = 3, connections = [[1,2,1],[1,3,6],[2,3,1]], u = 1, = 3
Output: 2
Explanation: the connection path is 1 -> 2 -> 3.
Output