Company: Harness_21nov
Difficulty: medium
Connect the Country 2 Problem Description There are n cities in a country, each with an associated cost given in an array called cost. The cost to build a bidirectional road between two cities i and j is the sum of their respective costs, cost[i] + cost[j]. Additionally, there are m offers available, each defined by a triplet [i, j, k], meaning a road can be built between cities i and j for a cost of k. You can choose to either use an offer or pay the sum of the costs to build a road between two cities. The goal is to determine the minimum cost required to ensure all cities are interconnected, meaning there is a path between every pair of cities. Examples Example 1: Input: n = 5, cost = [3, 1, 2, 3, 1], offers = [[3, 4, 1], [1, 5, 5]] Output: 10 Explanation: Optimally, you can build the roads as follows: - Build a road between cities 3 and 2, and pay the cost of cost[3] + cost[2] = 2 + 1 = 3 units. - Build a road between cities 3 and 4, and use the first offer to pay the cost of 1 unit