public static void main(String[] args) throws IOException {
    IO io = new IO(System.in);
    int sum;

    while (true) {

      int nV = io.nextInt();
      int nE = io.nextInt();
      if (nV == 0) {
        break;
      }
      V[] vertices = new V[nV];
      E[] edges = new E[nE];

      for (int j = 0; j < nV; j++) {
        vertices[j] = new V(j);
      }

      for (int j = 0; j < nE; j++) {
        int start = io.nextInt();
        int end = io.nextInt();
        double w = io.nextDouble();
        if (end > start) {
          edges[j] = new E(vertices[start], vertices[end], w);
        } else {
          edges[j] = new E(vertices[end], vertices[start], w);
        }
      }

      ArrayList<E> result = compute(nV, edges);
      if (result.size() > 0) {
        sum = 0;
        for (int i = 0; i < result.size(); i++) {
          sum += result.get(i).w;
        }
        io.println(sum);
        String[] resultStrings = new String[result.size()];
        for (int i = 0; i < result.size(); i++) {
          resultStrings[i] = "" + result.get(i).start.name + " " + result.get(i).end.name;
        }
        Arrays.sort(resultStrings);
        for (int i = 0; i < result.size(); i++) {
          io.printf("%s\n", resultStrings[i]);
        }
      } else {
        io.println("Impossible");
      }
    }

    io.close();
  }
Exemple #2
0
 protected void assertEqual(final Object expected, final Object actual) {
   if (!(Utils.equals(expected, actual))) {
     IO.print("Valor atingido (");
     IO.print(((Object) actual));
     IO.print(") diferente do esperado (");
     IO.print(((Object) expected));
     IO.println(")");
   } else {
     IO.print("Valor atingido (");
     IO.print(((Object) actual));
     IO.print(") corresponde ao esperado (");
     IO.print(((Object) expected));
     IO.println(")");
   }
 }
Exemple #3
0
 public void execute() throws InvalidOperation {
   List<Employee> employees = _entity.getListOfEmployees();
   Collections.sort(employees, new SortEmployeesByKey());
   for (Employee e : employees) {
     IO.println(e.toString());
   }
 }