#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;
const int N = 5e5 + 10, mod = 1e9 + 2;
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 |
7 ms |
12040 KB |
Output is correct |
2 |
Runtime error |
19 ms |
24272 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
11984 KB |
Output is correct |
2 |
Incorrect |
5 ms |
11984 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '115051492' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12040 KB |
Output is correct |
2 |
Runtime error |
19 ms |
24272 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3083 ms |
15680 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3083 ms |
15680 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 |
Incorrect |
5 ms |
11984 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '115051492' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12040 KB |
Output is correct |
2 |
Runtime error |
19 ms |
24272 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12040 KB |
Output is correct |
2 |
Runtime error |
19 ms |
24272 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |