#include<bits/stdc++.h>
#define MAXN 500007
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){
if(v[x].size()==0){
prod[x]=1; return;
}
prod[x]=1;
for(int i=0;i<v[x].size();i++){
dfs(v[x][i]);
prod[x]*=prod[v[x][i]];
prod[x]%=mod;
}
prod[x]*=2; 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]];
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:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i=0;i<v[x].size();i++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11984 KB |
Output is correct |
2 |
Incorrect |
5 ms |
11984 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
11984 KB |
Output is correct |
2 |
Correct |
5 ms |
12072 KB |
Output is correct |
3 |
Correct |
5 ms |
12112 KB |
Output is correct |
4 |
Correct |
6 ms |
12000 KB |
Output is correct |
5 |
Correct |
6 ms |
12112 KB |
Output is correct |
6 |
Correct |
6 ms |
12100 KB |
Output is correct |
7 |
Correct |
6 ms |
12112 KB |
Output is correct |
8 |
Correct |
7 ms |
12068 KB |
Output is correct |
9 |
Correct |
7 ms |
12060 KB |
Output is correct |
10 |
Correct |
6 ms |
12208 KB |
Output is correct |
11 |
Correct |
7 ms |
12112 KB |
Output is correct |
12 |
Correct |
6 ms |
12112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11984 KB |
Output is correct |
2 |
Incorrect |
5 ms |
11984 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3077 ms |
14992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3077 ms |
14992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
11984 KB |
Output is correct |
2 |
Correct |
5 ms |
12072 KB |
Output is correct |
3 |
Correct |
5 ms |
12112 KB |
Output is correct |
4 |
Correct |
6 ms |
12000 KB |
Output is correct |
5 |
Correct |
6 ms |
12112 KB |
Output is correct |
6 |
Correct |
6 ms |
12100 KB |
Output is correct |
7 |
Correct |
6 ms |
12112 KB |
Output is correct |
8 |
Correct |
7 ms |
12068 KB |
Output is correct |
9 |
Correct |
7 ms |
12060 KB |
Output is correct |
10 |
Correct |
6 ms |
12208 KB |
Output is correct |
11 |
Correct |
7 ms |
12112 KB |
Output is correct |
12 |
Correct |
6 ms |
12112 KB |
Output is correct |
13 |
Execution timed out |
3077 ms |
14992 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11984 KB |
Output is correct |
2 |
Incorrect |
5 ms |
11984 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11984 KB |
Output is correct |
2 |
Incorrect |
5 ms |
11984 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |