#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> haha[300001];
vector<long long> wut[300001];
vector<long long> bruh(300001);
vector<long long> dp(300001);
vector<long long> prod(300001);
const long long MOD = 1e9+2022;
long long n,m;
void dfs(long long a, long long t) {
long long br = 0,pr = 1,sb = 0,yeah = 0;
for(long long i = 0; i < wut[a].size(); i++) {
if(bruh[wut[a][i]]) {
br++;
}
yeah++;
}
for(long long v: haha[a]) {
if(v != t) {
dfs(v,a);
sb = (sb*prod[v]+dp[v]*pr)%MOD;
pr*=prod[v];
pr%=MOD;
yeah++;
}
}
prod[a] = (pr*yeah)%MOD;
dp[a] = (sb+br*pr)%MOD;
}
void init(int N, int M, vector<int> p, vector<int> a) {
n = N;
m = M;
for(long long i = n; i < n+m; i++) {
bruh[i] = a[i-n];
}
for(long long i = 1; i < n; i++) {
haha[i].push_back(p[i]);
haha[p[i]].push_back(i);
}
for(long long i = n; i < n+m; i++) {
wut[p[i]].push_back(i);
}
}
int count_ways(int l, int r) {
for(long long i = l; i <= r; i++) {
if(bruh[i]) {
bruh[i] = 0;
}
else {
bruh[i] = 1;
}
}
dfs(0,-1);
return dp[0];
}
Compilation message
circuit.cpp: In function 'void dfs(long long int, long long int)':
circuit.cpp:15:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(long long i = 0; i < wut[a].size(); i++) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
21344 KB |
Output is correct |
2 |
Correct |
9 ms |
21340 KB |
Output is correct |
3 |
Correct |
8 ms |
21456 KB |
Output is correct |
4 |
Correct |
9 ms |
21456 KB |
Output is correct |
5 |
Correct |
9 ms |
21456 KB |
Output is correct |
6 |
Correct |
9 ms |
21364 KB |
Output is correct |
7 |
Correct |
10 ms |
21456 KB |
Output is correct |
8 |
Correct |
9 ms |
21456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
21328 KB |
Output is correct |
2 |
Correct |
9 ms |
21456 KB |
Output is correct |
3 |
Correct |
10 ms |
21444 KB |
Output is correct |
4 |
Correct |
10 ms |
21436 KB |
Output is correct |
5 |
Correct |
9 ms |
21456 KB |
Output is correct |
6 |
Correct |
10 ms |
21456 KB |
Output is correct |
7 |
Correct |
11 ms |
21456 KB |
Output is correct |
8 |
Correct |
10 ms |
21456 KB |
Output is correct |
9 |
Correct |
10 ms |
21456 KB |
Output is correct |
10 |
Correct |
9 ms |
21596 KB |
Output is correct |
11 |
Correct |
9 ms |
21584 KB |
Output is correct |
12 |
Correct |
9 ms |
21392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
21344 KB |
Output is correct |
2 |
Correct |
9 ms |
21340 KB |
Output is correct |
3 |
Correct |
8 ms |
21456 KB |
Output is correct |
4 |
Correct |
9 ms |
21456 KB |
Output is correct |
5 |
Correct |
9 ms |
21456 KB |
Output is correct |
6 |
Correct |
9 ms |
21364 KB |
Output is correct |
7 |
Correct |
10 ms |
21456 KB |
Output is correct |
8 |
Correct |
9 ms |
21456 KB |
Output is correct |
9 |
Correct |
8 ms |
21328 KB |
Output is correct |
10 |
Correct |
9 ms |
21456 KB |
Output is correct |
11 |
Correct |
10 ms |
21444 KB |
Output is correct |
12 |
Correct |
10 ms |
21436 KB |
Output is correct |
13 |
Correct |
9 ms |
21456 KB |
Output is correct |
14 |
Correct |
10 ms |
21456 KB |
Output is correct |
15 |
Correct |
11 ms |
21456 KB |
Output is correct |
16 |
Correct |
10 ms |
21456 KB |
Output is correct |
17 |
Correct |
10 ms |
21456 KB |
Output is correct |
18 |
Correct |
9 ms |
21596 KB |
Output is correct |
19 |
Correct |
9 ms |
21584 KB |
Output is correct |
20 |
Correct |
9 ms |
21392 KB |
Output is correct |
21 |
Correct |
9 ms |
21456 KB |
Output is correct |
22 |
Correct |
9 ms |
21456 KB |
Output is correct |
23 |
Correct |
10 ms |
21456 KB |
Output is correct |
24 |
Correct |
10 ms |
21456 KB |
Output is correct |
25 |
Correct |
9 ms |
21456 KB |
Output is correct |
26 |
Correct |
10 ms |
21416 KB |
Output is correct |
27 |
Correct |
10 ms |
21456 KB |
Output is correct |
28 |
Correct |
10 ms |
21456 KB |
Output is correct |
29 |
Correct |
9 ms |
21456 KB |
Output is correct |
30 |
Correct |
12 ms |
21428 KB |
Output is correct |
31 |
Correct |
10 ms |
21456 KB |
Output is correct |
32 |
Correct |
10 ms |
21456 KB |
Output is correct |
33 |
Correct |
10 ms |
21440 KB |
Output is correct |
34 |
Correct |
10 ms |
21456 KB |
Output is correct |
35 |
Correct |
10 ms |
21456 KB |
Output is correct |
36 |
Correct |
10 ms |
21584 KB |
Output is correct |
37 |
Correct |
10 ms |
21608 KB |
Output is correct |
38 |
Correct |
10 ms |
21568 KB |
Output is correct |
39 |
Correct |
9 ms |
21456 KB |
Output is correct |
40 |
Correct |
10 ms |
21456 KB |
Output is correct |
41 |
Correct |
10 ms |
21412 KB |
Output is correct |
42 |
Correct |
9 ms |
21456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3095 ms |
23728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3095 ms |
23728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
21328 KB |
Output is correct |
2 |
Correct |
9 ms |
21456 KB |
Output is correct |
3 |
Correct |
10 ms |
21444 KB |
Output is correct |
4 |
Correct |
10 ms |
21436 KB |
Output is correct |
5 |
Correct |
9 ms |
21456 KB |
Output is correct |
6 |
Correct |
10 ms |
21456 KB |
Output is correct |
7 |
Correct |
11 ms |
21456 KB |
Output is correct |
8 |
Correct |
10 ms |
21456 KB |
Output is correct |
9 |
Correct |
10 ms |
21456 KB |
Output is correct |
10 |
Correct |
9 ms |
21596 KB |
Output is correct |
11 |
Correct |
9 ms |
21584 KB |
Output is correct |
12 |
Correct |
9 ms |
21392 KB |
Output is correct |
13 |
Execution timed out |
3095 ms |
23728 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
21344 KB |
Output is correct |
2 |
Correct |
9 ms |
21340 KB |
Output is correct |
3 |
Correct |
8 ms |
21456 KB |
Output is correct |
4 |
Correct |
9 ms |
21456 KB |
Output is correct |
5 |
Correct |
9 ms |
21456 KB |
Output is correct |
6 |
Correct |
9 ms |
21364 KB |
Output is correct |
7 |
Correct |
10 ms |
21456 KB |
Output is correct |
8 |
Correct |
9 ms |
21456 KB |
Output is correct |
9 |
Correct |
8 ms |
21328 KB |
Output is correct |
10 |
Correct |
9 ms |
21456 KB |
Output is correct |
11 |
Correct |
10 ms |
21444 KB |
Output is correct |
12 |
Correct |
10 ms |
21436 KB |
Output is correct |
13 |
Correct |
9 ms |
21456 KB |
Output is correct |
14 |
Correct |
10 ms |
21456 KB |
Output is correct |
15 |
Correct |
11 ms |
21456 KB |
Output is correct |
16 |
Correct |
10 ms |
21456 KB |
Output is correct |
17 |
Correct |
10 ms |
21456 KB |
Output is correct |
18 |
Correct |
9 ms |
21596 KB |
Output is correct |
19 |
Correct |
9 ms |
21584 KB |
Output is correct |
20 |
Correct |
9 ms |
21392 KB |
Output is correct |
21 |
Correct |
9 ms |
21456 KB |
Output is correct |
22 |
Correct |
9 ms |
21456 KB |
Output is correct |
23 |
Correct |
10 ms |
21456 KB |
Output is correct |
24 |
Correct |
10 ms |
21456 KB |
Output is correct |
25 |
Correct |
9 ms |
21456 KB |
Output is correct |
26 |
Correct |
10 ms |
21416 KB |
Output is correct |
27 |
Correct |
10 ms |
21456 KB |
Output is correct |
28 |
Correct |
10 ms |
21456 KB |
Output is correct |
29 |
Correct |
9 ms |
21456 KB |
Output is correct |
30 |
Correct |
12 ms |
21428 KB |
Output is correct |
31 |
Correct |
10 ms |
21456 KB |
Output is correct |
32 |
Correct |
10 ms |
21456 KB |
Output is correct |
33 |
Correct |
10 ms |
21440 KB |
Output is correct |
34 |
Correct |
10 ms |
21456 KB |
Output is correct |
35 |
Correct |
10 ms |
21456 KB |
Output is correct |
36 |
Correct |
10 ms |
21584 KB |
Output is correct |
37 |
Correct |
10 ms |
21608 KB |
Output is correct |
38 |
Correct |
10 ms |
21568 KB |
Output is correct |
39 |
Correct |
9 ms |
21456 KB |
Output is correct |
40 |
Correct |
10 ms |
21456 KB |
Output is correct |
41 |
Correct |
10 ms |
21412 KB |
Output is correct |
42 |
Correct |
9 ms |
21456 KB |
Output is correct |
43 |
Execution timed out |
3077 ms |
21584 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
21344 KB |
Output is correct |
2 |
Correct |
9 ms |
21340 KB |
Output is correct |
3 |
Correct |
8 ms |
21456 KB |
Output is correct |
4 |
Correct |
9 ms |
21456 KB |
Output is correct |
5 |
Correct |
9 ms |
21456 KB |
Output is correct |
6 |
Correct |
9 ms |
21364 KB |
Output is correct |
7 |
Correct |
10 ms |
21456 KB |
Output is correct |
8 |
Correct |
9 ms |
21456 KB |
Output is correct |
9 |
Correct |
8 ms |
21328 KB |
Output is correct |
10 |
Correct |
9 ms |
21456 KB |
Output is correct |
11 |
Correct |
10 ms |
21444 KB |
Output is correct |
12 |
Correct |
10 ms |
21436 KB |
Output is correct |
13 |
Correct |
9 ms |
21456 KB |
Output is correct |
14 |
Correct |
10 ms |
21456 KB |
Output is correct |
15 |
Correct |
11 ms |
21456 KB |
Output is correct |
16 |
Correct |
10 ms |
21456 KB |
Output is correct |
17 |
Correct |
10 ms |
21456 KB |
Output is correct |
18 |
Correct |
9 ms |
21596 KB |
Output is correct |
19 |
Correct |
9 ms |
21584 KB |
Output is correct |
20 |
Correct |
9 ms |
21392 KB |
Output is correct |
21 |
Correct |
9 ms |
21456 KB |
Output is correct |
22 |
Correct |
9 ms |
21456 KB |
Output is correct |
23 |
Correct |
10 ms |
21456 KB |
Output is correct |
24 |
Correct |
10 ms |
21456 KB |
Output is correct |
25 |
Correct |
9 ms |
21456 KB |
Output is correct |
26 |
Correct |
10 ms |
21416 KB |
Output is correct |
27 |
Correct |
10 ms |
21456 KB |
Output is correct |
28 |
Correct |
10 ms |
21456 KB |
Output is correct |
29 |
Correct |
9 ms |
21456 KB |
Output is correct |
30 |
Correct |
12 ms |
21428 KB |
Output is correct |
31 |
Correct |
10 ms |
21456 KB |
Output is correct |
32 |
Correct |
10 ms |
21456 KB |
Output is correct |
33 |
Correct |
10 ms |
21440 KB |
Output is correct |
34 |
Correct |
10 ms |
21456 KB |
Output is correct |
35 |
Correct |
10 ms |
21456 KB |
Output is correct |
36 |
Correct |
10 ms |
21584 KB |
Output is correct |
37 |
Correct |
10 ms |
21608 KB |
Output is correct |
38 |
Correct |
10 ms |
21568 KB |
Output is correct |
39 |
Correct |
9 ms |
21456 KB |
Output is correct |
40 |
Correct |
10 ms |
21456 KB |
Output is correct |
41 |
Correct |
10 ms |
21412 KB |
Output is correct |
42 |
Correct |
9 ms |
21456 KB |
Output is correct |
43 |
Execution timed out |
3095 ms |
23728 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |