이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |