#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
vector<vector<int>> adj(N);
for (int i = 0; i < M; ++i) {
adj[R[i][0]].push_back(R[i][1]);
adj[R[i][1]].push_back(R[i][0]);
}
auto node = [&](int u, int v) {
if (adj[v][0] == u)
return N+v;
else
return v;
};
const int J = 29;
vector<vector<int>> succ(J+1, vector<int>(2*N, -1));
for (int i = 0; i < N; ++i) {
succ[0][node(-1, i)] = node(i, adj[i][0]);
for (int v : adj[i]) {
if (v != adj[i][0] or adj[i].size() == 1)
succ[0][node(v, i)] = node(i, adj[i][0]);
else
succ[0][node(v, i)] = node(i, adj[i][1]);
}
}
for (int j = 1; j <= J; ++j) {
for (int u = 0; u < 2*N; ++u) {
succ[j][u] = succ[j-1][ succ[j-1][u] ];
}
}
for(int it = 0; it < Q; ++it) {
int K = G[it];
int cnt = 0;
for (int i = 0; i < N; ++i) {
int u = node(-1, i);
for (int j = J; j >= 0; --j) {
if (K & (1 << j)) u = succ[j][u];
}
if (u == P or u == N+P) ++cnt;
}
answer(cnt);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
9308 KB |
Output is correct |
12 |
Correct |
15 ms |
14092 KB |
Output is correct |
13 |
Correct |
24 ms |
27996 KB |
Output is correct |
14 |
Correct |
58 ms |
43036 KB |
Output is correct |
15 |
Correct |
62 ms |
43436 KB |
Output is correct |
16 |
Correct |
39 ms |
30296 KB |
Output is correct |
17 |
Correct |
35 ms |
26204 KB |
Output is correct |
18 |
Correct |
17 ms |
13916 KB |
Output is correct |
19 |
Correct |
56 ms |
42832 KB |
Output is correct |
20 |
Correct |
54 ms |
43356 KB |
Output is correct |
21 |
Correct |
40 ms |
30300 KB |
Output is correct |
22 |
Correct |
42 ms |
25948 KB |
Output is correct |
23 |
Correct |
71 ms |
47188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
9308 KB |
Output is correct |
12 |
Correct |
15 ms |
14092 KB |
Output is correct |
13 |
Correct |
24 ms |
27996 KB |
Output is correct |
14 |
Correct |
58 ms |
43036 KB |
Output is correct |
15 |
Correct |
62 ms |
43436 KB |
Output is correct |
16 |
Correct |
39 ms |
30296 KB |
Output is correct |
17 |
Correct |
35 ms |
26204 KB |
Output is correct |
18 |
Correct |
17 ms |
13916 KB |
Output is correct |
19 |
Correct |
56 ms |
42832 KB |
Output is correct |
20 |
Correct |
54 ms |
43356 KB |
Output is correct |
21 |
Correct |
40 ms |
30300 KB |
Output is correct |
22 |
Correct |
42 ms |
25948 KB |
Output is correct |
23 |
Correct |
71 ms |
47188 KB |
Output is correct |
24 |
Correct |
5 ms |
348 KB |
Output is correct |
25 |
Correct |
1454 ms |
9304 KB |
Output is correct |
26 |
Correct |
2468 ms |
13912 KB |
Output is correct |
27 |
Correct |
3201 ms |
27992 KB |
Output is correct |
28 |
Execution timed out |
5074 ms |
42836 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |