Submission #769981

#TimeUsernameProblemLanguageResultExecution timeMemory
769981vjudge1Klasika (COCI20_klasika)C++17
33 / 110
5058 ms4408 KiB
//YOU WILL MAKE IT #pragma GCC optimize("Ofast") #pragma GCC target("avx2") #include<bits/stdc++.h> using namespace std; const int N=1e5+2; int ans=0; int col=1; vector<pair<int,int>> graph[N]; int pa[N]; int vis[N]; void dfs(int i,int j,int p,int cur,bool f){ if(f||vis[i]==col) ans=max(ans,cur); for(auto h:graph[i]){ int x=h.first; if((x==p)||(x==pa[j]&&f)) continue; dfs(x,j,i,cur^(h.second),(f|(x==j))); } } void DFS(int i,int p){ vis[i]=col; for(auto h:graph[i]){ if(h.first!=p){ DFS(h.first,i); } } } void solve(){ int q;cin>>q; int n=2; while(q--){ string s;cin>>s; int x,y;cin>>x>>y; if(s[0]=='A'){ graph[n].push_back({x,y}); graph[x].push_back({n,y}); pa[n]=x; n++; } else{ col++; ans=0; if(y==1) DFS(y,-1); else DFS(y,pa[y]); dfs(x,y,-1,0,(x==y)); cout<<ans<<endl; } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...