Ejemplo n.º 1
0
  /*
  public static void main(String[] args) {
  	try {
  		// solve(args);
  		solve("-file=gc_70_5");
  	} catch (IOException e) {
  		e.printStackTrace();
  	}
  }
  */
  public static void solve(String args) throws IOException {
    String fileName = null;

    // get the temp file name
    // for (String arg : args) {
    if (args.startsWith("-file=")) {
      fileName = args.substring(6);
    }
    // }
    if (fileName == null) return;

    // read the lines out of the file
    List<String> lines = new ArrayList<String>();

    BufferedReader input = new BufferedReader(new FileReader(fileName));
    try {
      String line = null;
      while ((line = input.readLine()) != null) {
        lines.add(line);
      }
    } finally {
      input.close();
    }

    // parse the data in the file
    String[] firstLine = lines.get(0).split("\\s+");
    int nodes = Integer.parseInt(firstLine[0]);
    int edges = Integer.parseInt(firstLine[1]);

    g = new Graph(nodes, edges);
    g.initialiseGraph();

    for (int i = 1; i < edges + 1; i++) {
      String line = lines.get(i);
      String[] parts = line.split("\\s+");

      g.setEdges(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]));
    }

    noOfColors = g.getMaxDeg();
    // System.out.println(noOfColors);
    colorOfNode = new int[nodes];
    prevColorOfNode = new int[nodes];

    domainOfNode = new int[nodes][noOfColors];
    colorTheGraph(nodes);

    int colorsUsed = 0;
    for (int i = 0; i < nodes; i++) {
      int c = colorOfNode[i];
      if (c > colorsUsed) colorsUsed = c;
    }

    // System.out.println(noOfColors);
    // System.out.println(checkEverything(nodes));
    // prepare the solution in the specified output format

    System.out.println(colorsUsed + " " + 0);
    for (int i = 0; i < nodes; i++) {
      System.out.print(colorOfNode[i] + " ");
    }
    System.out.println("");
  }