#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI acos(-1)
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll dp[100005];
vll children[100005];
ll subtree[100005];
void dfs(ll u){
	subtree[u] = 1;
	for (auto v : children[u]){
		dfs(v); subtree[u] += subtree[v];
	}
	ll sum_pos_even = 0, sum_neg_even = 0;
	vll odd;
	dp[u] = 1;
	for (auto v : children[u]){
		if (subtree[v] & 1) odd.eb(dp[v]);
		else if (dp[v] < 0) sum_pos_even -= dp[v];
		else sum_neg_even += dp[v];
	}
	dp[u] -= sum_pos_even;
	if (odd.size() & 1) dp[u] -= sum_neg_even;
	else dp[u] += sum_neg_even;
	sort(odd.begin(), odd.end());
	for (ll i = 0; i < (ll) odd.size(); i++){
		if (i & 1) dp[u] -= odd[i];
		else dp[u] += odd[i];
	}
}
int main(){
	fastio;
	ll n; cin >> n;
	for (ll i = 2; i <= n; i++){
		ll p; cin >> p;
		children[p].eb(i);
	}
	dfs(1);
	cout << (n + dp[1]) / 2 << "\n";
}
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef map<ll, ll> ml;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';

struct mint{
  ll val;
  mint() {}
  mint(ll x) {val = mod(x, MOD);}
  mint operator-() {return mint(-this->val);}
  bool operator==(mint a) {return this->val == a.val;}
  bool operator<(mint a) {return this->val < a.val;}
  bool operator!=(mint a) {return this->val != a.val;}
  mint operator+(mint a) {return mint(this->val + a.val);}
  mint operator-(mint a) {return mint(this->val - a.val);}
  mint operator*(mint a) {return mint(this->val * a.val);}
  mint operator/(mint a) {return mint(this->val * a.inv().val);}
  mint &operator+=(mint a) {return *this = *this + a;}
  mint &operator-=(mint a) {return *this = *this - a;}
  mint &operator*=(mint a) {return *this = *this * a;}
  mint &operator/=(mint a) {return *this = *this / a;}
  friend istream &operator>>(istream &is, mint &m) {
    is >> m.val;
    return is;
  }
  friend ostream &operator<<(ostream &os, mint &m) {
    os << m.val;
    return os;
  }
  mint pow(ll n) {
    if(n == 0) return 1;
    if(n & 1) return pow(n-1) * *this;
    mint ret = pow(n/2);
    return ret * ret;
  }
  vector<mint> powv(ll n) {
    vector<mint> vec(n+1, 1);
    rep2(i, 1, n) vec[i] = vec[i-1] * *this;
    return vec;
  }
  mint inv() {return pow(MOD-2);}
  vector<mint> invv(ll n) {
    vector<mint> vec(n+1, 1);
    rep2(i, 2, n) vec[i] = -vec[MOD%i] * (MOD/i);
    return vec;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, p;
  cin >> n >> p;
  mint ans = mint(p-1)*(mint(p-2).pow(n-1));
  cout << ans << newl;
  return 0;
}