#include using namespace std; #define out(x) cout << #x << '=' << x << endl #define out2(x, y) cout << #x << '=' << x << ',' << #y << '=' << y << endl #define no cout << "No" << endl; return #define yes cout << "Yes" << endl; return #define outvec(a) for (int v : a) { cout << v << ' '; } cout << endl #define lowbit(x) (x & -x) #define gcd __gcd #define inf 0x3f3f3f3f3f3f3f3fLL #define infi 0x3f3f3f3f using ll = long long; using pii = pair; void solve() { int n, x, m; cin >> n >> x >> m; vector> graph(n + 1); vector p(n + 1); for (int i = 1; i <= n; i++) { cin >> p[i]; if (p[i] != -1) graph[p[i]].push_back(i); } vector v(n + 1); for (int i = 1; i <= n; i++) { cin >> v[i]; } int dfn = 0; vector dfns(n + 1); vector dfne(n + 1); vector idx(n + 1); function dfs = [&](int node) -> int { dfns[node] = dfne[node] = ++dfn; idx[dfn] = node; for (int next : graph[node]) { dfne[node] = dfs(next); } return dfne[node]; }; for (int i = 1; i <= n; i++) { if (p[i] == -1) { dfs(i); break; } } map mp; vector pre(n + 1); for (int i = 1; i <= n; i++) { pre[i] = pre[i - 1]; int back = v[idx[i]] ^ x; if (mp.count(back)) { pre[i] = max(pre[i], mp[back]); } mp[v[idx[i]]] = i; } for (int i = 1; i <= m; i++) { int q; cin >> q; int l = dfns[q]; int r = dfne[q]; if (pre[r] < l) { cout << "NO" << endl; } else { cout << "YES" << endl; } } } int main(void) { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { solve(); } }