//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
#define int long long
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2")

constexpr int mod = 998244353;
int st(int x,int n)
{
    if (n==0) return x%mod;
    int a = st(x,n-1);
    return ((a*a)%mod+mod)%mod;
}
int get_st(int x,int n)
{
    int ans=1;
    for (int i=30;i>=0;i--)
    {
        if ((1<<i)<=n)
        {
            int a = st(x,i);
            n -= (1<<i);
            ans = ((ans*a)%mod+mod)%mod;
        }
    }
    return ans;
}
vector<vector<int>> v;
vector<int> sz;
void dfs(int i)
{
    sz[i] = 1;
    for (auto j:v[i])
    {
        dfs(j);
        sz[i] += sz[j];
    }
}
signed main()
{
    int n,k;
    cin >> n >> k;
    int x;
    cin >> x;
    x--;
    v.resize(n);
    sz.resize(n);
    for (int i=0;i<n;i++)
    {
        int a;
        cin >> a;
        a--;
        v[a].push_back(i);
    }
    int ans=get_st(2,sz[x]);
    for (auto i:v[x])
    {
        ans = ((ans-get_st(2,sz[i]))%mod+mod)%mod;
    }
    cout << ans;
}
