Submission #861202

#TimeUsernameProblemLanguageResultExecution timeMemory
861202Trisanu_DasBirthday gift (IZhO18_treearray)C++17
0 / 100
196 ms262144 KiB
#include <bits/stdc++.h> using namespace std; int n, m, q, a[200005], vis[200005], par[200005]; vector<int> adj[200005]; void dfs(int u, int p){ vis[u] = vis[p] + 1; par[u] = p; for(auto v : adj[u]) if(v != p) dfs(v, u); } int lca(int v, int u){ if(vis[v] > vis[u]) lca(par[v], u); if(vis[u] > vis[v]) lca(par[u], v); if(v != u) lca(par[v], u); return v; } int main(){ cin >> n >> m >> q; for(int i = 0; i < n - 1; i++){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for(int i = 0; i < n; i++) cin >> a[i]; dfs(1, 0); while(q--){ int op; cin >> op; if(op == 1){ int idx, val; cin >> idx >> val; a[idx] = val; }else{ int l, r, v, ptr_l = -1, ptr_r = -1; cin >> l >> r >> v; for(int u = l; u <= r; u++){ if(u != r && lca(a[u], a[u + 1]) == v){ ptr_l = u; ptr_r = u + 1; break; }else if(a[u] == v){ ptr_l = u; ptr_r = u; break; } } cout << ptr_l << ' ' << ptr_r << '\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...