Minimum Spanning Tree Edge Weight Difference

Company: Navi Technologies

Difficulty: medium

Problem Statement

Minimum Spanning Tree Edge Weight Difference Problem Description A network has g_nodes nodes, labelled 1 to g_nodes , and g_edges undirected weighted links. Link i joins node g_from[i] and node g_to[i] and has weight g_weight[i] . Weights may be negative. A spanning tree is obtained by deleting links until exactly g_nodes - 1 links remain and every node can still reach every other node. The spread of a spanning tree is the weight of its heaviest link minus the weight of its lightest link. Find the smallest spread over all spanning trees of the network. If the network has no spanning tree at all, the answer is -1 . Note that the total weight of the tree does not matter; only the gap between its largest and smallest link weight counts. Function Description Complete the function findMinDifference in the editor. It has the following parameters: int g_nodes : the number of nodes int g_from[g_edges] : one end of each link int g_to[g_edges] : the other end of each link int g_weight[g_edges] :