import java.util.Scanner; public class Kcores { static final int MAXNODE = 1000; static public String kcoreElems(String [][] entries, int numEntries, String u) { String result = u; /* ------------------- INSERT CODE HERE ---------------------*/ /* -------------------- END OF INSERTION --------------------*/ return result; } static public void printEntries(String [][] entries, int numEntries) { for (int i = 0; i < numEntries; i++) { String node1 = entries[i][0]; System.out.print("Node " + node1 + " neighbors ="); int j = 1; 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 while (sc.hasNext()) { entry[idx++] = sc.next(); // 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 src = s.next(); // start node String core = kcoreElems(entries, numEntries, src); System.out.println(core); } } } catch(Exception e) { System.out.println("BAD INPUT FORMAT"); } } }