Language: C++

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
inline char nc() {
	return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f;
}
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
const int maxlog = 20;
int n;
int f[maxn][3];
int dfn[maxn], dfc; 
int dep[maxn], parent[maxn][maxlog];
int head[maxn];
vector<int> r[maxn];
vector<int> adj[maxn];
struct edge {
	int to, nex;
	edge(int to=0,int nex=0):to(to),nex(nex){}
};
vector<edge> G;
inline void addedge(int u, int v) {
	G.push_back(edge(v, head[u])), head[u] = G.size() - 1;
	G.push_back(edge(u, head[v])), head[v] = G.size() - 1;
}
inline int add(int x) {
	return x >= mod ? x - mod : x;
}
ll power(ll x, ll y) {
	ll re = 1;
	while(y) {
		if(y & 1) re = re * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return re;
}
void dfs(int u) {
	dfn[u] = ++dfc;
	r[dep[u]].push_back(u);
	for(int i = 1; i < maxlog; ++i) {
		parent[u][i] = parent[parent[u][i - 1]][i - 1];
	}
	for(int i = head[u]; ~i; i = G[i].nex) {
		int v = G[i].to; if(v == parent[u][0]) continue;
		dep[v] = dep[u] + 1;
		parent[v][0] = u;
		dfs(v);
	}
}
int lca(int u, int v) {
	if(dep[u] > dep[v]) swap(u, v);
	for(int i = maxlog - 1; ~i; --i) {
		if(dep[v] - dep[u] >= 1 << i) {
			v = parent[v][i];
		}
	}
	if(u == v) return u;
	for(int i = maxlog - 1; ~i; --i) {
		if(parent[u][i] != parent[v][i]) {
			u = parent[u][i];
			v = parent[v][i];
		}
	}
	return parent[u][0];
}
void dp(int u) {
	f[u][0] = 1; f[u][1] = !adj[u].size(), f[u][2] = 0;
	for(unsigned int i = 0; i < adj[u].size(); ++i) {
		int v = adj[u][i];
		dp(v);
		f[u][2] = ((ll)f[u][2] * (f[v][0] + f[v][1]) + (ll)f[u][1] * f[v][1]) % mod;
		f[u][1] = ((ll)f[u][0] * f[v][1] + (ll)f[u][1] * f[v][0]) % mod;
		f[u][0] = (ll)f[u][0] * f[v][0] % mod;
	}
	f[u][0] = add(f[u][0] + f[u][2]);
	adj[u].clear();
}
inline int cmp(const int &a, const int &b) {
	return dfn[a] < dfn[b];
}
inline void adde(int u, int v) {
	adj[u].push_back(v);
}
int sol(int x) {
	static int stk[maxn];
	sort(r[x].begin(), r[x].end(), cmp);
	int top = 0; stk[++top] = r[x][0];
	for(unsigned i = 1; i < r[x].size(); ++i) {
		int w = lca(stk[top], r[x][i]);
		while(top > 1 && dep[stk[top - 1]] > dep[w]) {
			adde(stk[top - 1], stk[top]), top--;
		}
		if(dep[stk[top]] > dep[w]) {
			adde(w, stk[top]), top--;
		}
		if(w != stk[top]) stk[++top] = w;
		stk[++top] = r[x][i];
	}
	while(top > 1) {
		adde(stk[top - 1], stk[top]), top--;
	}
	dp(stk[top]);
	return f[stk[top]][1];
}
int main() {
	read(n), n++;
	memset(head, -1, sizeof(head));
	for(int i = 2; i <= n; ++i) {
		int x; read(x), x++;
		addedge(x, i);
	}
	dfs(1);
	int an = 0;
	int x = 0;
	for(int i = 0; ; ++i) {
		if(!r[i].size()) break;
		x++;
		an = (an + power(2, n - r[i].size()) * sol(i)) % mod;
	}
	printf("%d\n", an);
	return 0;
} 

Compiler output:
a.cc:26:1: error: 'vector' does not name a type
   26 | vector<int> r[maxn];
      | ^~~~~~
a.cc:27:1: error: 'vector' does not name a type
   27 | vector<int> adj[maxn];
      | ^~~~~~
a.cc:32:1: error: 'vector' does not name a type
   32 | vector<edge> G;
      | ^~~~~~
a.cc: In function 'void addedge(int, int)':
a.cc:34:9: error: 'G' was not declared in this scope
   34 |         G.push_back(edge(v, head[u])), head[u] = G.size() - 1;
      |         ^
a.cc: In function 'void dfs(int)':
a.cc:51:9: error: 'r' was not declared in this scope
   51 |         r[dep[u]].push_back(u);
      |         ^
a.cc:55:38: error: 'G' was not declared in this scope
   55 |         for(int i = head[u]; ~i; i = G[i].nex) {
      |                                      ^
a.cc: In function 'void dp(int)':
a.cc:79:33: error: 'adj' was not declared in this scope; did you mean 'add'?
   79 |         f[u][0] = 1; f[u][1] = !adj[u].size(), f[u][2] = 0;
      |                                 ^~~
      |                                 add
a.cc: In function 'void adde(int, int)':
a.cc:94:9: error: 'adj' was not declared in this scope; did you mean 'add'?
   94 |         adj[u].push_back(v);
      |         ^~~
      |         add
a.cc: In function 'int sol(int)':
a.cc:98:14: error: 'r' was not declared in this scope
   98 |         sort(r[x].begin(), r[x].end(), cmp);
      |              ^
a.cc: In function 'int main()':
a.cc:128:21: error: 'r' was not declared in this scope
  128 |                 if(!r[i].size()) break;
      |                     ^
a.cc:130:41: error: 'r' was not declared in this scope
  130 |                 an = (an + power(2, n - r[i].size()) * sol(i)) % mod;
      |                                         ^