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;
#define ll long long
int const N=2e5+5;
int const mod=1e9+7;
vector<pair<int,int>> adj[N];
int par1[N];
int n=1;
int ss=0;
int ans=0;
void dfs1(int node,int xr=0,bool vs=0,int p=0){
if(node==ss)
vs=1;
if(vs)
ans=max(ans,xr);
for(auto [c,w]:adj[node]){
if(c!=p)
dfs1(c,xr^(w),vs,node);
}
}
void dfs2(int node,int xr=0,int p=0){
if(node==ss)
return;
ans=max(ans,xr);
for(auto [c,w]:adj[node]){
if(c!=p)
dfs2(c,xr^(w),node);
}
}
int main(){
int q;
cin>>q;
while(q--){
string s;
cin>>s;
if(s=="Add"){
n++;
int u,w;
cin>>u>>w;
par1[n]=u;
adj[u].push_back({n,w});
adj[n].push_back({u,w});
}
else{
int a,b;
cin>>a>>b;
int p=par1[a];
bool bl=0;
while(p!=0){
if(p==b)
bl=1;
p=par1[p];
}
if(bl){
ss=b;
dfs2(a);
cout<<ans<<endl;
ans=0;
ss=0;
}
else{
ss=b;
dfs1(a,0,0);
cout<<ans<<endl;
ans=0;
ss=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... |