Submission #861202

# Submission time Handle Problem Language Result Execution time Memory
861202 2023-10-15T16:08:45 Z Trisanu_Das Birthday gift (IZhO18_treearray) C++17
0 / 100
196 ms 262144 KB
#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 time Memory Grader output
1 Runtime error 196 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 196 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 196 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 196 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -