#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5, B = 20;
int n, m, p, q, adj[2][N];
pair<bool, int> dp[2][B][N];
int f(int x, int k) {
pair<int, int> pr = make_pair(0, x);
for (int i = 29; i >= 0; i--) {
if ((k >> i) & 1) {
pr = dp[pr.first][i][pr.second];
}
}
return pr.second;
}
void count_routes(int n, int m, int p, int R[][2], int q, int G[])
{
for (int i = 0; i < n; i++) {
adj[0][i] = adj[1][i] = -1;
}
for (int i = 0; i < m; i++) {
int x = R[i][0];
int y = R[i][1];
if (adj[0][x] == -1) {
adj[0][x] = adj[1][x] = y;
}
else if (adj[1][x] == adj[0][x]) {
adj[1][x] = y;
}
if (adj[0][y] == -1) {
adj[0][y] = adj[1][y] = x;
}
else if (adj[1][y] == adj[0][y]) {
adj[1][y] = x;
}
}
for (int i = 0; i < n; i++) {
int x = adj[0][i];
if (x == -1) {
dp[0][0][i] = make_pair(0, i);
}
else {
dp[0][0][i] = make_pair((adj[0][x] == i), x);
}
x = adj[1][i];
if (x == -1) {
dp[1][0][i] = make_pair(0, i);
}
else {
dp[1][0][i] = make_pair((adj[0][x] == i), x);
}
}
for (int i = 1; i < B; i++) {
for (int j = 0; j < n; j++) {
pair<int, int> mid = dp[0][i-1][j];
dp[0][i][j] = dp[mid.first][i-1][mid.second];
mid = dp[1][i-1][j];
dp[1][i][j] = dp[mid.first][i-1][mid.second];
}
}
cin >> q;
for (int i = 0; i < q; i++) {
int x = G[i];
int ans = 0;
for (int j = 0; j < n; j++) {
if (f(j, x) == p) ans++;
}
answer(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
65880 KB |
Output is correct |
2 |
Correct |
8 ms |
65880 KB |
Output is correct |
3 |
Correct |
9 ms |
65884 KB |
Output is correct |
4 |
Correct |
7 ms |
66016 KB |
Output is correct |
5 |
Correct |
7 ms |
65884 KB |
Output is correct |
6 |
Correct |
9 ms |
65884 KB |
Output is correct |
7 |
Correct |
7 ms |
65884 KB |
Output is correct |
8 |
Correct |
8 ms |
65880 KB |
Output is correct |
9 |
Correct |
9 ms |
65884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
65880 KB |
Output is correct |
2 |
Correct |
8 ms |
65880 KB |
Output is correct |
3 |
Correct |
9 ms |
65884 KB |
Output is correct |
4 |
Correct |
7 ms |
66016 KB |
Output is correct |
5 |
Correct |
7 ms |
65884 KB |
Output is correct |
6 |
Correct |
9 ms |
65884 KB |
Output is correct |
7 |
Correct |
7 ms |
65884 KB |
Output is correct |
8 |
Correct |
8 ms |
65880 KB |
Output is correct |
9 |
Correct |
9 ms |
65884 KB |
Output is correct |
10 |
Correct |
7 ms |
65884 KB |
Output is correct |
11 |
Correct |
12 ms |
66252 KB |
Output is correct |
12 |
Incorrect |
21 ms |
66760 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
65880 KB |
Output is correct |
2 |
Correct |
8 ms |
65880 KB |
Output is correct |
3 |
Correct |
9 ms |
65884 KB |
Output is correct |
4 |
Correct |
7 ms |
66016 KB |
Output is correct |
5 |
Correct |
7 ms |
65884 KB |
Output is correct |
6 |
Correct |
9 ms |
65884 KB |
Output is correct |
7 |
Correct |
7 ms |
65884 KB |
Output is correct |
8 |
Correct |
8 ms |
65880 KB |
Output is correct |
9 |
Correct |
9 ms |
65884 KB |
Output is correct |
10 |
Correct |
7 ms |
65884 KB |
Output is correct |
11 |
Correct |
12 ms |
66252 KB |
Output is correct |
12 |
Incorrect |
21 ms |
66760 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |