#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<pair<int, int>>G[N];
#define UNIQUE_SORT(vec) do { \
sort((vec).begin(), (vec).end()); \
(vec).erase(unique((vec).begin(), (vec).end()), (vec).end()); \
} while(0)
int b, answer = 0;
void dfs(int node, int parent, int ans, bool B)
{
if (node == b)B = true;
if (B)
{
answer = max(answer, ans);
}
for (auto i : G[node])
{
if (i.first == parent)continue;
dfs(i.first, node, ans ^ i.second, B);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int q;
cin >> q;
int cnt = 1;
while (q--)
{
string s;
cin >> s;
if (s == "Add")
{
int x, y;
cin >> x >> y;
cnt++;
G[x].push_back({ cnt, y });
G[cnt].push_back({ x, y });
}
else
{
int a, bb;
cin >> a >> bb;
b = bb;
dfs(a, -1, 0, 0);
cout << answer << "\n";
answer = 0;
}
}
return 0;
}
# | 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... |