#include<bits/stdc++.h>
#define MAXN 100007
using namespace std;
const long long mod=1000002022;
int n;
long long black[MAXN],white[MAXN];
long long prod[MAXN];
vector<int> v[MAXN];
void dfs(int x){
prod[x]=int(v[x].size())+1;
if(v[x].size()==0)return;
for(int i=0;i<v[x].size();i++){
dfs(v[x][i]);
prod[x]*=prod[v[x][i]];
prod[x]%=mod;
}
black[x]=0;
/* c=2 */ black[x]+=black[v[x][0]]*black[v[x][1]];
/* c=1 */ black[x]+=black[v[x][0]]*black[v[x][1]]+black[v[x][0]]*white[v[x][1]]+white[v[x][0]]*black[v[x][1]];
/* c=0 */ black[x]+=prod[v[x][0]]*prod[v[x][1]];
black[x]%=mod;
white[x]=(prod[x]-black[x]+mod)%mod;
}
void init(int N, int M,vector<int> P,vector<int> A){
n=N+M;
for(int i=1;i<n;i++){
v[P[i]].push_back(i);
}
for(int i=0;i<M;i++){
if(A[i]==0){
black[i+N]=0; white[i+N]=1;
}else{
black[i+N]=1; white[i+N]=0;
}
}
}
int count_ways(int L, int R){
for(int i=L;i<=R;i++){
swap(black[i],white[i]);
}
dfs(0);
return black[0];
}
/*
int main(){
init(15, 16, {-1, 0, 0, 1, 1, 2, 2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15}, {0, 1, 1, 1,1,1,1,1,1, 1, 1, 1,1,1,1,1});
}
*/
Compilation message
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(int i=0;i<v[x].size();i++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3055 ms |
5572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3055 ms |
5572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |