docs: public static int findOptimalRoot(int[] msg) {
      final int size = (msg.length >> 1) + 1;
      int[] depth = new int[size], missing = new int[size];
  
      // We shouldn't need more iterations in any case ever.
      int root = -1;
      for(int i = 1; i < size; i++) {
        boolean active = false;
        for(int e = 1; e < msg.length; e += 2) {
          if(depth[msg[e - 1]] == 0) {
            missing[msg[e]]++;
          }
          if(depth[msg[e]] == 0) {
            missing[msg[e - 1]]++;
          }
        }
        for(int n = 0; n < size; n++) {
          if(depth[n] == 0 && missing[n] <= 1) {
            depth[n] = i;
            root = n;
            active = true;
          }
        }
        if(!active) {
          break;
        }
        Arrays.fill(missing, 0); // Clean up.
      }
      return root;
    }