static List<Integer> compute_equival_classes(int n, List<Integer> A,
	                                    List<Integer> B) {
	  // Each element maps to itself.
	  List<Integer> F = new ArrayList<Integer>();
	  iota(F, n, 0);

	  for (int i = 0; i < A.size(); ++i) {
	    int a = backtrace(F, A.get(i)), b = backtrace(F, B.get(i));
	    if (a < b) {
	    	F.set(b, a);
	    } else {
	    	F.set(a, b);
	    }
	  }

	  // Generates the weakest equivalence relation.
	  for (int f : F) {
	    while (f != F.get(f)) {
	      f = F.get(f);
	    }
	  }
	  return F;
	}