#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 state[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 count_ways(int, int)':
circuit.cpp:33:7: warning: unused variable 'd' [-Wunused-variable]
33 | int d=dfs(0);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
596 KB |
Possible tampering with the output or unexpected termination of the program |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Possible tampering with the output or unexpected termination of the program |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
596 KB |
Possible tampering with the output or unexpected termination of the program |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
4060 KB |
Possible tampering with the output or unexpected termination of the program |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
4060 KB |
Possible tampering with the output or unexpected termination of the program |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Possible tampering with the output or unexpected termination of the program |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
596 KB |
Possible tampering with the output or unexpected termination of the program |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
596 KB |
Possible tampering with the output or unexpected termination of the program |
2 |
Halted |
0 ms |
0 KB |
- |