#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3qplfh5 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using tupiii=tuple<int,int,int>;
using pii=pair<int,int>;
using vi=vector<int>;
using vll=vector<long long>;
int main(){
_3qplfh5;
int q;
cin>>q;
vec(tupiii) qry;
int n=1;
rep(_,q){
string s;
cin>>s;
int t=0;
if(s=="Add"){
t=1;
n++;
}
int _a,_b;
cin>>_a>>_b;
qry.pb({t,_a,_b});
}
vec(vec(pii)) adj(n);
int now=1;
for(auto [t,_a,_b] : qry){
if(t==1){
adj[_a-1].pb({now,_b});
adj[now].pb({_a-1,_b});
now++;
}
}
//rabbit tour
vi tour;
vi tin(n,0),tout(n,0);
vi psum(n,0);
int tm=0;
auto dfs=[&](auto self,int v,int par)->void{
tin[v]=tm++;
tour.pb(v);
for(auto edge : adj[v]){
int u=edge.fi;
if(u!=par){
psum[u]=psum[v]^edge.se;
// cout<<edge.se<<"\n";
self(self,u,v);
}
}
tout[v]=tm++;
tour.pb(v);
};
dfs(dfs,0,-1);
int frm,to;
int ans=0;
vi usd(n,0);
usd[0]=1;
auto walk=[&](auto self,int v,int par,int path,bool vis)->void{
vis=vis or v==to;
if(vis) ans=max(ans,path);
for(auto edge : adj[v]){
int u=edge.fi;
if(u!=par and usd[u]){
self(self,u,v,path^edge.se,vis);
}
}
};
now=1;
for(auto [t,_a,_b] : qry){
if(t==0){
_a--,_b--;
frm=_a,to=_b;
ans=0;
walk(walk,frm,-1,0,0);
cout<<ans<<"\n";
}else{
usd[now]=1;
now++;
}
}
//
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5088 ms |
9340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |