public class Dijkstra { // Dijkstra's algorithm to find shortest path from s to all other nodes public static int [] dijkstra (WeightedGraph G, int s) { final int [] dist = new int [G.size()]; // shortest known distance from "s" final int [] pred = new int [G.size()]; // preceeding node in path final boolean [] visited = new boolean [G.size()]; // all false initially for (int i=0; i d) { dist[v] = d; pred[v] = next; } } } return pred; // (ignore pred[s]==0!) } private static int minVertex (int [] dist, boolean [] v) { int x = Integer.MAX_VALUE; int y = -1; // graph not connected, or no unvisited vertices for (int i=0; i