@@ -0,0 +1,1799 @@
+//https://www.hackerrank.com/challenges/journey-to-the-moon%0Aimport java.io.*;%0Aimport java.util.*;%0A%0Apublic class Solution %7B%0A  public static void main(String%5B%5D args) throws IOException %7B%0A    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));%0A    %0A    //Get number of astronauts%0A    String%5B%5D line = br.readLine().split(%22 %22);%0A    final int N = Integer.parseInt(line%5B0%5D);%0A    %0A    //Initialize each astronaut's compatriots%0A    final List%3CList%3CInteger%3E%3E compatriots = new ArrayList%3CList%3CInteger%3E%3E(N);%0A    for(int i = 0; i %3C N; ++i)%7B%0A      compatriots.add(new ArrayList%3CInteger%3E());%0A    %7D%0A    %0A    //Get each astronaut's compatriots%0A    for(short L = Short.parseShort(line%5B1%5D); L %3E 0; --L)%7B%0A      line = br.readLine().split(%22 %22);%0A      final int A = Integer.parseInt(line%5B0%5D);%0A      final int B = Integer.parseInt(line%5B1%5D);%0A      compatriots.get(A).add(B);%0A      compatriots.get(B).add(A);%0A    %7D%0A    %0A    //Visit each %22country%22 (group of compatriots) and get the size%0A    boolean%5B%5D isVisited = new boolean%5BN%5D;%0A    List%3CInteger%3E countrySizes = new ArrayList%3CInteger%3E();%0A    for(int i = 0; i %3C N; ++i)%7B%0A      int countrySize = 0;%0A      final Queue%3CInteger%3E q = new ArrayDeque%3CInteger%3E();%0A      q.add(i);%0A      do %7B%0A        int astronautId = q.poll();%0A        if(!isVisited%5BastronautId%5D)%7B%0A          ++countrySize;%0A          isVisited%5BastronautId%5D = true;%0A          q.addAll(compatriots.get(astronautId));%0A        %7D%0A      %7D while (!q.isEmpty());%0A      if(countrySize %3E 0)%7B%0A        countrySizes.add(countrySize);%0A      %7D%0A    %7D%0A    %0A    //Get number of possible pairs%0A    long numPairs = 0L;%0A    long numPartners = N;%0A    for(int countrySize : countrySizes)%7B%0A      numPairs += countrySize * (numPartners -= countrySize);%0A    %7D%0A    %0A    //Print output%0A    System.out.print(numPairs);%0A  %7D%0A%7D%0A

Create journey-to-the-moon.java