Language: C++

#include <bits/stdc++.h>
using namespace std;
constexpr int P = 1'000'000'007;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  int n, i2 = (P + 1) / 2;;
  cin >> n;
  vector<vector<int>> graph(n+1);
  for (int i = 1, p; i <= n; ++i) {
    cin >> p;
    graph[p].push_back(i);
  }
  function<array<int, 2>(int)> dfs = [&](int u) {
    array<int, 2> res;
    int z = 0;
    for (int v : graph[u]) {
      auto rhs = dfs(v);
      if (rhs.size() > res.size())
        swap(rhs, res);
      z = max(z, (int) rhs.size());
      for (int depth = 0; depth < (int) rhs.size(); ++depth) {
        res[depth][1] = ((int64_t) res[depth][1] * rhs[depth][0] + (int64_t) res[depth][0] * rhs[depth][1]) % P;
        res[depth][0] = (int64_t) res[depth][0] * rhs[depth][0] % P;
      }
    }
    for (int depth = 0; depth < z; ++z)
      res[depth][0] = (1 + P - res[depth][1]) % P;
    res.push_front({i2, i2});
    return res;
  };
  int p2 = 1;
  for (int i = 0; i <= n; ++i)
    (p2 *= 2) %= P;
  int ans = 0;
  auto dp = dfs(0);
  for (auto d : dp)
    (ans += d[1]) %= P;
  cout << (int64_t) ans * p2 % P << '\n';
  return 0;
}

Compiler output:
a.cc: In lambda function:
a.cc:24:19: error: invalid types 'std::array<int, 2>::value_type {aka int}[int]' for array subscript
   24 |         res[depth][1] = ((int64_t) res[depth][1] * rhs[depth][0] + (int64_t) res[depth][0] * rhs[depth][1]) % P;
      |                   ^
a.cc:24:46: error: invalid types 'std::array<int, 2>::value_type {aka int}[int]' for array subscript
   24 |         res[depth][1] = ((int64_t) res[depth][1] * rhs[depth][0] + (int64_t) res[depth][0] * rhs[depth][1]) % P;
      |                                              ^
a.cc:24:62: error: invalid types 'std::array<int, 2>::value_type {aka int}[int]' for array subscript
   24 |         res[depth][1] = ((int64_t) res[depth][1] * rhs[depth][0] + (int64_t) res[depth][0] * rhs[depth][1]) % P;
      |                                                              ^
a.cc:24:88: error: invalid types 'std::array<int, 2>::value_type {aka int}[int]' for array subscript
   24 |         res[depth][1] = ((int64_t) res[depth][1] * rhs[depth][0] + (int64_t) res[depth][0] * rhs[depth][1]) % P;
      |                                                                                        ^
a.cc:24:104: error: invalid types 'std::array<int, 2>::value_type {aka int}[int]' for array subscript
   24 |         res[depth][1] = ((int64_t) res[depth][1] * rhs[depth][0] + (int64_t) res[depth][0] * rhs[depth][1]) % P;
      |                                                                                                        ^
a.cc:25:19: error: invalid types 'std::array<int, 2>::value_type {aka int}[int]' for array subscript
   25 |         res[depth][0] = (int64_t) res[depth][0] * rhs[depth][0] % P;
      |                   ^
a.cc:25:45: error: invalid types 'std::array<int, 2>::value_type {aka int}[int]' for array subscript
   25 |         res[depth][0] = (int64_t) res[depth][0] * rhs[depth][0] % P;
      |                                             ^
a.cc:25:61: error: invalid types 'std::array<int, 2>::value_type {aka int}[int]' for array subscript
   25 |         res[depth][0] = (int64_t) res[depth][0] * rhs[depth][0] % P;
      |                                                             ^
a.cc:29:17: error: invalid types 'std::array<int, 2>::value_type {aka int}[int]' for array subscript
   29 |       res[depth][0] = (1 + P - res[depth][1]) % P;
      |                 ^
a.cc:29:42: error: invalid types 'std::array<int, 2>::value_type {aka int}[int]' for array subscript
   29 |       res[depth][0] = (1 + P - res[depth][1]) % P;
      |                                          ^
a.cc:30:9: error: 'struct std::array<int, 2>' has no member named 'push_front'
   30 |     res.push_front({i2, i2});
      |         ^~~~~~~~~~
a.cc: In function 'int main()':
a.cc:39:14: error: invalid types 'int[int]' for array subscript
   39 |     (ans += d[1]) %= P;
      |              ^