import java.util.Scanner; public class Navigation { static final int MAXNODE = 1000; static void findPathWeight(String [][] entries, int numEntries, String u, String v) { double answer = 1.0/0.0; /* ------------------- INSERT CODE HERE ---------------------*/ /* -------------------- END OF INSERTION --------------------*/ System.out.println(u + " " + v + " " + ((answer == 1.0 / 0.0)?"NONE":answer)); } static public void printEntries(String [][] entries, int numEntries) { for (int i = 0; i < numEntries; i++) { String node1 = entries[i][0]; int nodeType = Integer.parseInt(entries[i][1]); System.out.print("Node " + node1 + " type = " + nodeType); if(entries[i][2] != null) { float wt = Float.parseFloat(entries[i][2]); System.out.print(" w/ edges of weight " + wt + " to neighbors ="); int j = 3; while (entries[i][j] != null) { String node2 = entries[i][j]; System.out.print(" " + node2); j++; } } System.out.println(); } } static public void main(String [] args) { // read the graph Scanner inp = new Scanner(System.in); try { String line = inp.nextLine(); if (!line.equals("GRAPH BEGIN")) throw new Exception(); while (inp.hasNext()) { if (!inp.hasNext()) throw new Exception(); // found new graph String [][] entries = new String [MAXNODE][]; int numEntries = 0; while (inp.hasNext()) { String ln = inp.nextLine(); if (ln.equals("GRAPH END")) //* end of graph specification break; String [] entry = new String[MAXNODE]; int idx = 0; // read in entry (on single line) Scanner sc = new Scanner(ln); if(!sc.hasNext()) throw new Exception(); entry[idx++] = sc.next(); // node if(!sc.hasNext()) throw new Exception(); entry[idx++] = sc.next(); // node type if(sc.hasNext()) { entry[idx++] = sc.next(); // weight of edges to while (sc.hasNext()) { entry[idx++] = sc.next(); // these neighbors } } entry[idx] = null; entries[numEntries++] = entry; // save entry } // printEntries(entries, numEntries); // process lines after graph, if any while (inp.hasNext()) { line = inp.nextLine(); if (line.equals("GRAPH BEGIN")) { break; } Scanner s = new Scanner(line); String u = s.next(); // start node String v = s.next(); // end node findPathWeight(entries, numEntries, u, v); } } } catch(Exception e) { System.out.println("BAD INPUT FORMAT"); } } }