Submission #770005

#TimeUsernameProblemLanguageResultExecution timeMemory
770005vjudge1Klasika (COCI20_klasika)C++17
33 / 110
5049 ms9040 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "C:\GCC\debug.h" #else #define debug(...) void(42) #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int q; cin >> q; vector<vector<int>> adj(q + 1); vector<int> pref(q + 1); auto Add = [&](int x, int y, int w) { adj[x].push_back(y); pref[y] = pref[x] ^ w; }; int cnt = 1; for (int i = 0; i < q; i++) { string type; cin >> type; if (type == "Add") { int x, w; cin >> x >> w; --x; Add(x, cnt, w); ++cnt; } else { int a, b; cin >> a >> b; --a, --b; int res = 0; function<void(int, bool)> Dfs = [&](int u, bool insideSubtree) { bool isOk = insideSubtree; if (u == b) { isOk = true; } if (isOk) { res = max(res, pref[a] ^ pref[u]); } for (auto v : adj[u]) { Dfs(v, isOk); } }; Dfs(0, false); cout << res << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...