#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) {
    used[v] = 1;
    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;
}

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);
    }
    vector<ll> pows(n + 1);
    pows[0] = 1;
    for (ll i = 1; i <= n; i++) {
        pows[i] = (pows[i - 1] * 2) % mod;
    }
    ll res = pows[cnt - 1];
    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 + ((pows[sum - 1] * sum % mod) * pows[c[i] - 1] % mod) * c[i]) % mod;
        sum += c[i];
    }
    cout << res << '\n';
}


