int f[v];

int dfs( int v ) {
  if (f[v] != 0)
    return f[v];
  f[v] = 1;
  for (int x : c[v])
    f[v] = max(f[v], dfs(x) + 1);
  return f[v];
}

int res = 0;
for (int i = 0; i < n; i++)
  res = max(res, f(i));