Submission #334044

#TimeUsernameProblemLanguageResultExecution timeMemory
334044ronnithKlasika (COCI20_klasika)C++14
33 / 110
129 ms1388 KiB
#include <bits/stdc++.h> typedef long long ll; #define trav(a, b) for(auto a : b) #define v vector #define vl vector<ll> #define mk make_pair #define f first #define s second using namespace std; vector<pair<int, int>> adj[2000]; int vis[2000]; int crr; void ff(int x, int pr, bool flag){ if(x == crr)flag = true; if(flag){ vis[x] = 1; } trav(e, adj[x]){ if(e.f != pr)ff(e.f, x, flag); } } int ans = 0; void dfs(int x, int pr, int level){ if(vis[x]) ans = max(ans, level); trav(e, adj[x]){ if(e.f != pr){ dfs(e.f, x, level ^ e.s); } } } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int q; cin >> q; string x; int a, b, size = 1; while(q --){ cin >> x >> a >> b; if(x == "Add"){ adj[a - 1].push_back(mk(size, b)); adj[size].push_back(mk(a - 1, b)); size ++; } else { crr = b - 1; for(int i = 0;i < size;i ++)vis[i] = 0; ff(0, -1, false); ans = 0; dfs(a - 1, -1, 0); cout << ans << '\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...