Submission #844546

#TimeUsernameProblemLanguageResultExecution timeMemory
844546vjudge1Klasika (COCI20_klasika)C++17
33 / 110
115 ms1400 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 2e3 + 5; int newnode = 2; vector < pair < int , int > > graph[N],child[N]; vector < int > possible; int find_x(int node , int past , int x){ if(node == x)return 0; int ret = -1; for(auto itr : graph[node]){ if(itr.first == past)continue; int cand = find_x(itr.first , node , x); if(cand != -1)ret = cand ^ itr.second; } return ret; } void vectorize(int node , int zor){ //cout << "vectorize : " << node << " " << zor << " / ";for(auto itr : child[node])cout << itr.first << "-" << itr.second << " ";cout << endl; possible.push_back(zor); for(auto itr : child[node]){ vectorize(itr.first,zor ^ itr.second); } } void add(int x , int y){ graph[x].push_back({newnode,y}); graph[newnode].push_back({x,y}); child[x].push_back({newnode,y}); newnode++; } int query(int a , int b){ int n1 = find_x(a,0,b); possible.clear(); vectorize(b,0); //cout << "n1 : " << n1 << endl; //cout << "possible : ";for(auto itr : possible)cout << itr << " ";cout << endl; int ans = 0; for(auto itr : possible){ ans = max(ans , n1 ^ itr); } return ans; } void solve(){ int q;cin >> q; while(q--){ string typ;cin >> typ; int q1,q2;cin >> q1 >> q2; if(typ == "Add"){ add(q1,q2); } else{ cout << query(q1,q2) << endl; } } } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); int testcase = 1;//cin >> testcase; while(testcase--)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...