#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;
const int N = 2e5 + 5, mod = 1000002022;
vector<int> adj[N];
int64_t dp[N][2], color[N], in[N], s[N], tt = 0;
void dfs(int u) {
s[u] = 1;
in[u] = tt++;
assert(adj[u].size() == 2 || adj[u].size() == 0);
if(adj[u].size() == 0) {
if(color[u]) dp[u][0] = 0, dp[u][1] = 1;
else dp[u][0] = 1, dp[u][1] = 0;
return;
}
int v1 = adj[u][0], v2 = adj[u][1];
dfs(v1);
dfs(v2);
s[u] += s[v1];
s[u] += s[v2];
dp[u][1] = dp[v1][1] * dp[v2][1] % mod * 2 % mod + (dp[v1][0] * dp[v2][1]) % mod + (dp[v1][1] * dp[v2][0]) % mod;
dp[u][1] %= mod;
dp[u][0] = dp[v1][0] * dp[v2][0] % mod * 2 % mod + (dp[v1][0] * dp[v2][1]) % mod + (dp[v1][1] * dp[v2][0]) % mod;
dp[u][0] %= mod;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
for(int i = 1; i < N + M; ++i) {
adj[P[i]].push_back(i);
}
for(int i = 0; i < M; ++i) color[i + N] = A[i];
}
int count_ways(int L, int R) {
for(int i = L; i <= R; ++i) {
color[i] ^= 1;
}
dfs(0);
return dp[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Runtime error |
6 ms |
9936 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5128 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
4 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Runtime error |
6 ms |
9936 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3082 ms |
8648 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3082 ms |
8648 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5128 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
4 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
13 |
Execution timed out |
3082 ms |
8648 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Runtime error |
6 ms |
9936 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Runtime error |
6 ms |
9936 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |