#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const ll mod = 998244353;
ll x;

void dfs(ll v, vector<bool> &used, vector<ll> &is, vector<ll> &p) {
    if (v == x) is[v] = 1;
    if (v == 0) return;
    if (!used[p[v]]) dfs(p[v], used, is, p);
    if (is[p[v]]) is[v] = is[p[v]] + 1;
}

ll binpow(ll x, ll n) {
    if (n == 0) return 1;
    if (n == 1) return x;
    ll t = binpow(x, n / 2);
    t = (t * t) % mod;
    if (n % 2) t = (t * x) % mod;
    return t;
}

int main() {
    ll n, k;
    cin >> n >> k;
    cin >> x;
    x--;
    vector<ll> p(n);
    for (ll i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }
    vector<bool> used(n);
    vector<ll> is(n);
    for (ll i = 0; i < n; i++) {
        if (!used[i]) dfs(i, used, is, p);
    }
    ll cnt = 0;
    for (ll i : is) {
        cnt += (i != 0);
    }
    ll res = (binpow(2, cnt - 1)) % mod;
    vector<ll> c;
    for (ll i = 1; i < n; i++) {
        if (p[i] == x) {
            c.push_back(is[i] - 1);
        }
    }
    sort(c.begin(), c.end());
    ll sum = c[0];
    for (ll i = 1; i < (ll) c.size(); i++) {
        res = (res + ((binpow(2, sum - 1) * sum % mod) * binpow(2, c[i] - 1) % mod) * c[i]) % mod;
        sum += c[i];
    }
    cout << res << '\n';
}


