@Override
    public void reduce(IntWritable key, Iterable<IntWritable> values,
        Context context) throws IOException, InterruptedException {
      // put all neighbors in a list
      ArrayList<Integer> neighbors = new ArrayList<Integer>();
      for (IntWritable nb : values) {
        neighbors.add(nb.get());
      }
      // output all possible candidates
      int numNeighbors = neighbors.size();
      for (int i = 0; i < numNeighbors; i ++) {
        int nb1 = neighbors.get(i);
        for (int j = i+1; j < numNeighbors; j ++) {
          int nb2 = neighbors.get(j);
          if (nb1 > nb2) {
            outValue.set(nb1, nb2);
          } else {
            outValue.set(nb2, nb1);
          }
          context.write(key, outValue);
        }
      }
    }