solution.cpp 1.6 KB
Newer Older
CSDN问答's avatar
CSDN问答 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#include <bits/stdc++.h>

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<int, int>;


void solve() {
	int n, x, m;
	cin >> n >> x >> m;
	vector<vector<int>> graph(n + 1);
	
	vector<int> p(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
		if (p[i] != -1) graph[p[i]].push_back(i);
	}
	
	vector<int> v(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
	}
	int dfn = 0;
	vector<int> dfns(n + 1);
	vector<int> dfne(n + 1);
	vector<int> idx(n + 1);
	function<int(int)> 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<int, int> mp;
	vector<int> 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();
	}
}