(Hacker Rank) Kruskal (MST): Really Special Subtree - Solution
Link to the problem: https://www.hackerrank.com/challenges/kruskalmstrsub This problem requires to find the minimum spanning tree of the given graphs using Kruskal's algorithm. Although the problem gives a stating node, the solution below starts using the edge whose weight is the minimum. import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static ArrayList<Edge> edges; public static int[] nodeParent; public static int[] depth; public static int root(int n) { while (n != nodeParent[n]) { n = nodeParent[n]; } return n; } public static boolean union(int ...
Comments
Post a Comment