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 F first
#define S second
#define int long long
#define pb push_back
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
pair<int,pair<int,int> > a[N];
int ans[N],p[N];
vector<int>adj[N];
int mux=-1e18;
void dfs(int node,int par,int a){
mux=max(mux,ans[node]^ans[a]);
for(auto x:adj[node]){
if(x==par)
continue;
dfs(x,node,a);
}
}
main()
{
int q;
cin>>q;
ans[1]=0;
int num=2;
p[1]=0;
while(q--){
string s;
cin>>s;
if(s=="Add"){
int x,y;
cin>>x>>y;
adj[x].pb(num);
ans[num]=ans[x]^y;
p[num]=x;
num++;
}
else{
int x,y;
cin>>x>>y;
mux=-1e18;
dfs(y,p[y],x);
cout<<mux<<endl;
}
/*for(int i=1;i<num;i++){
cout<<i<<": ";
for(auto x:adj[i])
cout<<x<<" ";
cout<<endl;*/
}
return 0;
}
Compilation message (stderr)
klasika.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main()
| ^~~~
# | 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... |