#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 |
0 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 |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
9308 KB |
Output is correct |
12 |
Correct |
15 ms |
13928 KB |
Output is correct |
13 |
Correct |
24 ms |
27996 KB |
Output is correct |
14 |
Correct |
56 ms |
42868 KB |
Output is correct |
15 |
Correct |
57 ms |
43348 KB |
Output is correct |
16 |
Correct |
40 ms |
30288 KB |
Output is correct |
17 |
Correct |
37 ms |
26192 KB |
Output is correct |
18 |
Correct |
18 ms |
13992 KB |
Output is correct |
19 |
Correct |
53 ms |
42832 KB |
Output is correct |
20 |
Correct |
63 ms |
43348 KB |
Output is correct |
21 |
Correct |
72 ms |
30288 KB |
Output is correct |
22 |
Correct |
40 ms |
25944 KB |
Output is correct |
23 |
Correct |
58 ms |
47192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
9308 KB |
Output is correct |
12 |
Correct |
15 ms |
13928 KB |
Output is correct |
13 |
Correct |
24 ms |
27996 KB |
Output is correct |
14 |
Correct |
56 ms |
42868 KB |
Output is correct |
15 |
Correct |
57 ms |
43348 KB |
Output is correct |
16 |
Correct |
40 ms |
30288 KB |
Output is correct |
17 |
Correct |
37 ms |
26192 KB |
Output is correct |
18 |
Correct |
18 ms |
13992 KB |
Output is correct |
19 |
Correct |
53 ms |
42832 KB |
Output is correct |
20 |
Correct |
63 ms |
43348 KB |
Output is correct |
21 |
Correct |
72 ms |
30288 KB |
Output is correct |
22 |
Correct |
40 ms |
25944 KB |
Output is correct |
23 |
Correct |
58 ms |
47192 KB |
Output is correct |
24 |
Correct |
5 ms |
344 KB |
Output is correct |
25 |
Correct |
1614 ms |
9560 KB |
Output is correct |
26 |
Correct |
2759 ms |
13916 KB |
Output is correct |
27 |
Correct |
3374 ms |
29008 KB |
Output is correct |
28 |
Execution timed out |
5021 ms |
44628 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |