#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
int N,M;
vector<vector<int>> tree;
vector<int> state;
vector<int> poss;
int dfs(int i){
if(tree[i][0]>=N) {
return tate[tree[i][0]]+state[tree[i][1]];
}
int l=dfs(tree[i][0]),r=dfs(tree[i][1]);
int lv=poss[tree[i][0]], rv=poss[tree[i][1]];
poss[i]=(2*lv*rv)+(lv*(2-rv))+rv*(2-lv);
return max(l,1)+max(r,1);
}
void init(int n, int m, std::vector<int> P, std::vector<int> A) {
N=n; M=m;
tree.resize(N+M); state.resize(N+M);
for (int i = 1; i < N+M; i++) tree[P[i]].push_back(i);
for (int i = N; i < N+M; i++) state[i] = A[i-N];
}
int count_ways(int L, int R) {
poss.clear(); poss.resize(N+M,0);
for (int i = L; i <= R; i++) state[i] = 1-state[i];
int d=dfs(0);
cout << poss[2]<<"\n";
return poss[0];
}
Compilation message
circuit.cpp: In function 'int dfs(int)':
circuit.cpp:14:12: error: 'tate' was not declared in this scope; did you mean 'state'?
14 | return tate[tree[i][0]]+state[tree[i][1]];
| ^~~~
| state
circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:33:7: warning: unused variable 'd' [-Wunused-variable]
33 | int d=dfs(0);
| ^