code: private static int getMaxDepth(int[][] adjlist, int v, int prev) {
          int longest = 0;
          for (int w : adjlist[v]) {
              if (w == prev) continue;
              // no cycles so don't need to check previous
              int length = getMaxDepth(adjlist, w, v);
              if (length > longest)
                  longest = length;
          }
          return 1 + longest;
      }
docs: Depth-First-Search on an acyclic graph. Since we have no cycles we
  don't need the visit flags and only need to know which atom we came from.
  
  @param adjlist adjacency list representation of grah
  @param v       the current atom index
  @param prev    the previous atom index
  @return the max length traversed