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>
#define endl "\n"
#define pb push_back
#define int long long
using namespace std;
const int inf = 2e18 + 5;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
vector<pair<int, int> > adj[N];
vector<int> child[N];
map<int,int> vis;
vector<pair<int,int> > val;
void dfs(int node, int ih){
if(vis[node]) return;
vis[node] = 1;
val.pb({ih, node});
for(auto itr: adj[node]){
dfs(itr.first, (ih ^ itr.second));
}
}
map<int,int> c;
void cbul(int node){
c[node] = 1;
for(auto itr: child[node]) cbul(itr);
}
int32_t main(){
//freopen("in.txt","r", stdin);
int q;
cin>>q;
int ncnt = 1;
while(q--){
string s;
cin>>s;
if(s == "Add"){
int x, y;
cin>>x>>y;
ncnt++;
adj[ncnt].pb({x, y});
adj[x].pb({ncnt, y});
child[x].pb(ncnt);
}
else{
int a, b;
cin>>a>>b;
vis.clear();
c.clear();
val.clear();
int ans = 0;
dfs(a, 0);
cbul(b);
for(auto itr: val){
if(c[itr.second]){
ans = max(ans, itr.first);
}
}
cout<<ans<<endl;
}
}
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... |