#include #include #include class TreeHeight { int n; std::vector parent; public: void read() { std::cin >> n; parent.resize(n); for (int i = 0; i < n; i++) std::cin >> parent[i]; } int compute_height() { // Replace this code with a faster implementation int maxHeight = 0; for (int vertex = 0; vertex < n; vertex++) { int height = 0; for (int i = vertex; i != -1; i = parent[i]) height++; maxHeight = std::max(maxHeight, height); } return maxHeight; } }; int main() { std::ios_base::sync_with_stdio(0); TreeHeight tree; tree.read(); std::cout << tree.compute_height() << std::endl; }