#include #include #include #include #include using namespace std; using Mint = atcoder::modint1000000007; int main() { int N; cin >> N; vector> adj(N); for (int i = 1; i < N; i++) { int v; cin >> v; --v; adj[v].push_back(i); cout << v << " " << i << endl; } function(int, int)> dfs = [&](int a, int h) { Mint root = 1, rem = 1; // case rem, child should all be rem // case root, n/c about child for (auto b : adj[a]) { auto [bro, bre] = dfs(b, h + 1); rem *= bre; root *= bre + bro; } if (h <= 1) rem = 0; return make_pair(root, rem); }; cout << dfs(0, 0).first.val() << endl; }