#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
#define pb push_back
int n = 1;
const int N = 5003;
vector <int> adj[N];
int a[N], p[N];
int dist[N], st[N];
int ans;
void dfs(int node, int p, int cur) {
	ans = max(ans, cur);
	for (auto i : adj[node]) if (i != p) {
		dfs(i, node, cur ^ a[i]);
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int q; cin >> q;
	while (q--) {
		string s; cin >> s;
		int x, b; cin >> x >> b;
		if (s[0] == 'A') {
			++n;
			a[n] = b;
			st[n] = st[x] ^ a[n];
			p[n] = x;
			adj[x].pb(n);
			adj[n].pb(x);
		}
		else {
			int st_d = st[x] ^ st[b];
			for (int i = 1; i <= n; ++i) {
				dist[i] = 0;
			}
			ans = st_d;
			dfs(b, p[b], st_d);
			cout << ans << "\n";
		}
	}
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |