Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws FileNotFoundException {
- /* Read an edge-weighted graph from a file */
- EdgeWeightedGraph ewg = new EdgeWeightedGraph(
- new Scanner(new File("/home/aldin-sxr/Downloads/tinyEWG.txt")));
- /* Instantiate the lazy Prim's algorithm */
- LazyPrimMST prim = new LazyPrimMST(ewg);
- /* Print out MST edges*/
- Iterable<Edge> edges = prim.edges();
- for (Edge e: edges) {
- System.out.println("(" +
- e.either() + ", " +
- e.other(e.either()) + ") - " + e.weight());
- }
- /* Print out MST weight */
- System.out.println("MST weight: " + prim.weight());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement