#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;
int n, m, P, k, ans = 0;
vector<int> adj[150005];
int succ[300005][20];
void initsucc() {
for (int j = 1; j < 20; j++) {
for (int i = 0; i < 2*n; i++) {
succ[i][j] = succ[succ[i][j-1]][j-1];
}
}
}
void calc(int a) {
for (int i = 0; i < 20; 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++) {
k = G[j];
ans = 0;
for (int i = 0; i < n; i++) {
calc(i);
}
answer(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3932 KB |
Output is correct |
2 |
Correct |
2 ms |
3932 KB |
Output is correct |
3 |
Correct |
2 ms |
3928 KB |
Output is correct |
4 |
Correct |
1 ms |
3932 KB |
Output is correct |
5 |
Correct |
3 ms |
4184 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 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 |
3932 KB |
Output is correct |
2 |
Correct |
2 ms |
3932 KB |
Output is correct |
3 |
Correct |
2 ms |
3928 KB |
Output is correct |
4 |
Correct |
1 ms |
3932 KB |
Output is correct |
5 |
Correct |
3 ms |
4184 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 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 |
3928 KB |
Output is correct |
11 |
Correct |
9 ms |
8284 KB |
Output is correct |
12 |
Incorrect |
23 ms |
11856 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3932 KB |
Output is correct |
2 |
Correct |
2 ms |
3932 KB |
Output is correct |
3 |
Correct |
2 ms |
3928 KB |
Output is correct |
4 |
Correct |
1 ms |
3932 KB |
Output is correct |
5 |
Correct |
3 ms |
4184 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 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 |
3928 KB |
Output is correct |
11 |
Correct |
9 ms |
8284 KB |
Output is correct |
12 |
Incorrect |
23 ms |
11856 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |