This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int par[N], val[N], res, cur;
bool in_sub[N][N];
vector<pair<int, int>> g[N];
void dfs(int v, int b, int p = -1){
if (in_sub[b][v])
res = max(res, cur);
for (auto [w, u] : g[v]){
if (u == p) continue;
cur ^= w;
dfs(u, b, v);
cur ^= w;
}
}
int main(){
int q;
cin >> q;
int n = 1;
par[n] = -1;
in_sub[1][1] = 1;
while (q--){
string s;
cin >> s;
if (s[0] == 'A'){
int x, y;
cin >> x >> y;
int v = ++n;
par[v] = x;
val[v] = y;
int p = v;
while (p != -1){
in_sub[p][v] = 1;
p = par[p];
}
g[x].push_back({y, v});
g[v].push_back({y, x});
}
else{
int a, b;
cin >> a >> b;
res = 0;
cur = 0;
dfs(a, b);
cout << res << endl;
}
}
}
# | 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... |