Language: C++

#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
int N, Max;
int P[200005];
int DP[200005];
const int MOD = 1000000007;
vector <int> G[200005];
int L[200005], Level[200005];
int Power[200005], cnt;
struct State{
int x[3];
State()
{
    for(int i = 0; i < 3; i++)
        x[i] = 0;
}
};
vector <State> D[200005];
int Depth[200005];
int Pos[200005];
void Read()
{
    cin >> N;
    Power[0] = 1;
    for(int i = 1; i <= N + 1; i++)
        Power[i] = (1LL * Power[i - 1] * 2) % MOD;
    for(int i = 1; i <= N; i++)
    {
        cin >> P[i];
        G[P[i]].push_back(i);
    }
    L[0] = 1;
}

void DFS(int node, int father)
{
    if(node != 0)
    {
        Level[node] = Level[father] + 1;
        L[Level[node]]++;
        Max = max(Max, Level[node]);
    }
    for(int i = 0; i < G[node].size(); i++)
    {
        int neighb = G[node][i];

        DFS(neighb, node);
        Depth[node] = max(Depth[node], Depth[neighb]);
    }
    ++Depth[node];
}
inline void Add(int& x, int y)
{
    x += y;
    if(x >= MOD)
        x -= MOD;
}
inline void sub(int& x, int y)
{
    x -= y;
    if( x < 0)
        x += MOD;
}
inline bool cmp(int a, int b)
{
    return Depth[a] < Depth[b];
}

void Merge(int a, int b)
{
    for(int i = 0; i < D[a].size(); i++)
    {
        State p = D[a][i], q = D[b][i], res;
        for(int j = 0; j < 3; j++)
            for(int k = 0; k < 3; k++)
                Add(res.x[min(j + k, 2)], (1LL * p.x[j] * q.x[k]) % MOD);
        D[b][i] = res;
    }
}

void DFS2(int node)
{
    int Max = 0, PMax = 0;
    for(int i = 0; i < G[node].size(); i++)
    {
        int neighb = G[node][i];
        DFS2(neighb);
        if(Depth[neighb] > Max)
        {
            Max = Depth[neighb];
            PMax = neighb;
        }
    }
    if(G[node].size() == 0)
    {
        ++cnt;
        int x[] = {1, 1, 0};
        State p;
        for(int i = 0; i < 3; i++)
            p.x[i] = x[i];
        Pos[node] = cnt;
        D[Pos[node]].emplace(D[Pos[node]].begin(), p);

        return;
    }
    Pos[node] = Pos[PMax];
    int m = 0;
    for(int i = 0; i < G[node].size(); i++)
    {
        int neighb = G[node][i];
        if(neighb == PMax)
            continue;
        m = max(m, D[Pos[neighb]].size());
        Merge(Pos[neighb], Pos[node]);
        D[Pos[neighb]].clear();
    }
    for(int j = 0; j < m; j++)
    {
        Add(D[Pos[node]][j].x[0], D[Pos[node]][j].x[2]);
        D[Pos[node]][j].x[2] = 0;
    }
    int x[] = {1, 1, 0};
        State p;
        for(int i = 0; i < 3; i++)
            p.x[i] = x[i];
    D[Pos[node]].emplace(D[Pos[node]].begin(), p);
}
int main()
{
    Read();
    DFS(0, -1);
    DFS2(0);
    int ans = 0;
    for(int i = 0; i < D[Pos[0]].size(); i++)
    {
        int aux = Power[N - L[i] + 1];
        Add(ans, (1LL * aux * D[Pos[0]][i].x[1]) % MOD);
    }
    cout << ans << '\n';
    return 0;
}


Compiler output:
a.cc: In function 'void DFS2(int)':
a.cc:116:16: error: no matching function for call to 'max(int&, std::vector<State>::size_type)'
  116 |         m = max(m, D[Pos[neighb]].size());
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:116:16: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<State>::size_type' {aka 'long unsigned int'})
  116 |         m = max(m, D[Pos[neighb]].size());
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:116:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  116 |         m = max(m, D[Pos[neighb]].size());
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~