This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
ID: antwand1
TASK: barn1
LANG: C++
*/
#include <bits/stdc++.h>
#define ll long long
#define du long double
#define F first
#define S second
using namespace std;
const int N=1e6+100;
vector<pair<int,int>> g[N];
int sz=1,mx=0;
bool ok[N];
void dfs(int u,int p,int we)
{
if(ok[u])mx=max(mx,we);
for(auto x:g[u]){
if(x.F!=p){
dfs(x.F,u,we^x.S);
}
}
}
void dfs2(int u,int p,int tar)
{
// cout<<u<<" "<<tar<<endl;
if(tar==u)tar=0;
if(tar==0)ok[u]=1;
for(auto x:g[u]){
if(x.F!=p){
dfs2(x.F,u,tar);
}
}
}
main()
{
//freopen("barn1.in","r",stdin);freopen("barn1.out","w",stdout);
int n;
cin>>n;
while(n--){
string s;
cin>>s;
if(s=="Add"){
sz++;
int a,b;
cin>>a>>b;
g[sz].push_back({a,b});
g[a].push_back({sz,b});
}
else{
for(int i=1;i<=sz;i++){
// cout<<i<<" :";
// for(auto x:g[i])cout<<x.F<<" ";cout<<endl;
}
int a,b;
cin>>a>>b;
for(int i=1;i<=sz;i++)ok[i]=0;
dfs2(1,1,b);
// for(int i=1;i<=sz;i++)cout<<ok[i]<<" ";cout<<endl;
mx=0;
dfs(a,a,0);
cout<<mx<<endl;
}
}
}
Compilation message (stderr)
klasika.cpp:37:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | 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... |