#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;
int n, m, P, ans = 0;
vector<int> adj[150005];
int succ[300005][31];
void initsucc() {
for (int j = 1; j < 31; j++) {
for (int i = 0; i <= 2*n; i++) {
succ[i][j] = succ[succ[i][j-1]][j-1];
}
}
}
void calc(int a, int k) {
for (int i = 0; i < 31; i++) {
if (k & (1 << i)) {
a = succ[a][i];
}
}
if (a == P || a == P+n) {
ans++;
}
}
void count_routes(int N, int M, int pp, int R[][2], int Q, int G[]) {
n = N, m = M, P = pp;
for (int i = 0; i < m; i++) {
if (adj[R[i][0]].size() < 2) {
adj[R[i][0]].push_back(R[i][1]);
}
if (adj[R[i][1]].size() < 2) {
adj[R[i][1]].push_back(R[i][0]);
}
}
for (int i = 0; i < n; i++) {
if (adj[i].size() == 1) {
if (i == adj[adj[i][0]][0]) {
succ[i][0] = adj[i][0]+n;
} else {
succ[i][0] = adj[i][0];
}
succ[i+n][0] = succ[i][0];
} else {
if (i == adj[adj[i][0]][0]) {
succ[i][0] = adj[i][0]+n;
} else {
succ[i][0] = adj[i][0];
}
if (i == adj[adj[i][1]][0]) {
succ[i+n][0] = adj[i][1]+n;
} else {
succ[i+n][0] = adj[i][1];
}
}
}
initsucc();
for (int j = 0; j < Q; j++) {
ans = 0;
for (int i = 0; i < n; i++) {
calc(i, G[j]);
}
answer(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
3972 KB |
Output is correct |
5 |
Correct |
2 ms |
3932 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
3932 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
3 ms |
4188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
3972 KB |
Output is correct |
5 |
Correct |
2 ms |
3932 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
3932 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
3 ms |
4188 KB |
Output is correct |
10 |
Correct |
2 ms |
3932 KB |
Output is correct |
11 |
Correct |
16 ms |
10536 KB |
Output is correct |
12 |
Correct |
30 ms |
15100 KB |
Output is correct |
13 |
Correct |
48 ms |
28820 KB |
Output is correct |
14 |
Correct |
89 ms |
43612 KB |
Output is correct |
15 |
Correct |
89 ms |
44116 KB |
Output is correct |
16 |
Correct |
59 ms |
31572 KB |
Output is correct |
17 |
Correct |
71 ms |
27496 KB |
Output is correct |
18 |
Correct |
22 ms |
15192 KB |
Output is correct |
19 |
Correct |
93 ms |
43604 KB |
Output is correct |
20 |
Correct |
123 ms |
44248 KB |
Output is correct |
21 |
Correct |
62 ms |
31440 KB |
Output is correct |
22 |
Correct |
52 ms |
27404 KB |
Output is correct |
23 |
Correct |
106 ms |
47908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
3972 KB |
Output is correct |
5 |
Correct |
2 ms |
3932 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
3932 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
3 ms |
4188 KB |
Output is correct |
10 |
Correct |
2 ms |
3932 KB |
Output is correct |
11 |
Correct |
16 ms |
10536 KB |
Output is correct |
12 |
Correct |
30 ms |
15100 KB |
Output is correct |
13 |
Correct |
48 ms |
28820 KB |
Output is correct |
14 |
Correct |
89 ms |
43612 KB |
Output is correct |
15 |
Correct |
89 ms |
44116 KB |
Output is correct |
16 |
Correct |
59 ms |
31572 KB |
Output is correct |
17 |
Correct |
71 ms |
27496 KB |
Output is correct |
18 |
Correct |
22 ms |
15192 KB |
Output is correct |
19 |
Correct |
93 ms |
43604 KB |
Output is correct |
20 |
Correct |
123 ms |
44248 KB |
Output is correct |
21 |
Correct |
62 ms |
31440 KB |
Output is correct |
22 |
Correct |
52 ms |
27404 KB |
Output is correct |
23 |
Correct |
106 ms |
47908 KB |
Output is correct |
24 |
Correct |
9 ms |
3932 KB |
Output is correct |
25 |
Correct |
3376 ms |
10564 KB |
Output is correct |
26 |
Execution timed out |
5042 ms |
15248 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |