在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ There are You are given Return the minimum cost so that for every pair of cities, there exists a path of connections (possibly of length 1) that connects those two cities together. The cost is the sum of the connection costs used. If the task is impossible, return -1.
Example 1: Input: N = 3, connections = [[1,2,5],[1,3,6],[2,3,1]] Output: 6 Explanation: Choosing any 2 edges will connect all cities so we choose the minimum 2. Example 2: Input: N = 4, connections = [[1,2,3],[3,4,4]] Output: -1 Explanation: There is no way to connect all cities even if all edges are used. Note:
想象一下你是个城市基建规划者,地图上有 给你一些可连接的选项 返回使得每对城市间都存在将它们连接在一起的连通路径(可能长度为 1 的)最小成本。该最小成本应该是所用全部连接代价的综合。如果根据已知条件无法完成该项任务,则请你返回 -1。 示例 1: 输入:N = 3, conections = [[1,2,5],[1,3,6],[2,3,1]] 输出:6 解释: 选出任意 2 条边都可以连接所有城市,我们从中选取成本最小的 2 条。 示例 2: 输入:N = 4, conections = [[1,2,3],[3,4,4]] 输出:-1 解释: 即使连通所有的边,也无法连接所有城市。 提示:
|
请发表评论