(SPOJ) Rede ótica - Solution 2
If you want to see another solution for this problem, click here . In order to solve this problem, I used Prim's algorithm. While reading the edges, I store them in an adjacency list. Then, I call the Prim method, which choose the next edge to be examined according to its cost. import java.io.*; import java.util.*; import java.text.DecimalFormat; class Main { public static HashMap<Integer, ArrayList<Edge>> adjList; public static Comparator<Edge> costComparator = new Comparator<Edge>() { public int compare(Edge e1, Edge e2) { if ((e1.cost - e2.cost) < 0) { return -1; } else if ((e1.co...