Language: C++

#include <bits/stdc++.h>
using namespace std;

vector< vector<int> > array;

long long solve(int x)
{
    if (array[x].size() == 0) {
        return 0LL;
    } else {
        long long ans = 0;
        for (int i = 0; i < array[x].size(); i++) {
            ans = max(ans, solve(array[x][i]) + 1, array[x].size());
        }
        return ans;
    }
}


int main()
{
    long long N;
    scanf("%lld", &N);
    vector<long long> a(N + 1);
    array.resize(N + 1);
    for (long long i = 2; i <= N; i++) {
        scanf("%lld", &a[i]);  //winner a[i], loser i;
        array[a[i]].push_back(i);
    }
    long long ans = solve(1);
    printf("%lld\n", ans);
}

Compiler output:
a.cc: In function 'long long int solve(int)':
a.cc:8:9: error: reference to 'array' is ambiguous
    8 |     if (array[x].size() == 0) {
      |         ^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:4:23: note:                 'std::vector<std::vector<int> > array'
    4 | vector< vector<int> > array;
      |                       ^~~~~
a.cc:12:29: error: reference to 'array' is ambiguous
   12 |         for (int i = 0; i < array[x].size(); i++) {
      |                             ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:4:23: note:                 'std::vector<std::vector<int> > array'
    4 | vector< vector<int> > array;
      |                       ^~~~~
a.cc:13:34: error: reference to 'array' is ambiguous
   13 |             ans = max(ans, solve(array[x][i]) + 1, array[x].size());
      |                                  ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:4:23: note:                 'std::vector<std::vector<int> > array'
    4 | vector< vector<int> > array;
      |                       ^~~~~
a.cc:13:52: error: reference to 'array' is ambiguous
   13 |             ans = max(ans, solve(array[x][i]) + 1, array[x].size());
      |                                                    ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:4:23: note:                 'std::vector<std::vector<int> > array'
    4 | vector< vector<int> > array;
      |                       ^~~~~
a.cc: In function 'int main()':
a.cc:25:5: error: reference to 'array' is ambiguous
   25 |     array.resize(N + 1);
      |     ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:4:23: note:                 'std::vector<std::vector<int> > array'
    4 | vector< vector<int> > array;
      |                       ^~~~~
a.cc:28:9: error: reference to 'array' is ambiguous
   28 |         array[a[i]].push_back(i);
      |         ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:4:23: note:                 'std::vector<std::vector<int> > array'
    4 | vector< vector<int> > array;
      |                       ^~~~~
a.cc: In function 'long long int solve(int)':
a.cc:17:1: warning: control reaches end of non-void function [-Wreturn-type]
   17 | }
      | ^