Submission #861210

# Submission time Handle Problem Language Result Execution time Memory
861210 2023-10-15T16:34:39 Z Trisanu_Das Birthday gift (IZhO18_treearray) C++17
Compilation error
0 ms 0 KB
# include <bits/stdc++.h>>
using namespace std;
 
int n, m, q, par[200005], g[200005] = {-1}, a[200005];
vector<int> adj[200005];
 
void dfs(int u, int p) {
	g[u] = g[p] + 1;
	par[u] = p;
	for(auto v : adj[u]) if(v != p) dfs(v, u);
}
 
int lca(int v, int u) {
	if(g[v] > g[u]) return lca(p[v], u);
	if(g[v] < g[u]) return lca(v, p[u]);
	if(v != u) return lca(p[v], u);
	return v;
}
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m >> q;
	for (int i = 1; i < n; i++){
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for (int i = 1; i < m + 1; 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 = x; ptr_r = x + 1;
					break;
                } else if(a[u] == v){
                    ptr_l = u; ptr_r = x;
					break;
				}
			}
			cout << ptr_l << ' ' << ptr_r << '\n';
		}
	}
}

Compilation message

treearray.cpp:1:26: warning: extra tokens at end of #include directive
    1 | # include <bits/stdc++.h>>
      |                          ^
treearray.cpp: In function 'int lca(int, int)':
treearray.cpp:14:29: error: 'p' was not declared in this scope
   14 |  if(g[v] > g[u]) return lca(p[v], u);
      |                             ^
treearray.cpp:15:32: error: 'p' was not declared in this scope
   15 |  if(g[v] < g[u]) return lca(v, p[u]);
      |                                ^
treearray.cpp:16:24: error: 'p' was not declared in this scope
   16 |  if(v != u) return lca(p[v], u);
      |                        ^
treearray.cpp: In function 'int main()':
treearray.cpp:40:14: error: 'x' was not declared in this scope
   40 |      ptr_l = x; ptr_r = x + 1;
      |              ^
treearray.cpp:43:40: error: 'x' was not declared in this scope
   43 |                     ptr_l = u; ptr_r = x;
      |                                        ^