#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "garden.h"
#include "gardenlib.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 3e5 + 10;
vector <pair <int, int>> e[N];
int to[N][30];
//void answer(int x) {
// cout << x << '\n';
//}
void count_routes(int n, int m, int p, int r[][2], int q, int g[]) {
vector <pair <int, int>> edges;
for (int i = 0; i < m; ++i) {
e[r[i][0]].push_back({r[i][1], i << 1});
e[r[i][1]].push_back({r[i][0], i << 1 ^ 1});
edges.push_back({r[i][0], r[i][1]});
edges.push_back({r[i][1], r[i][0]});
}
for (int i = 0; i < m * 2; ++i) {
auto [u, v] = edges[i];
to[i][0] = -1;
for (auto [w, j]: e[v]) {
if (i / 2 == j / 2) continue;
to[i][0] = j;
break;
}
if (to[i][0] == -1) to[i][0] = e[v][0].second;
}
for (int lg = 1; lg <= 29; ++lg) {
for (int i = 0; i < m * 2; ++i)
to[i][lg] = to[to[i][lg - 1]][lg - 1];
}
for (int id = 0; id < q; ++id) {
int x = g[id];
int ans = 0;
for (int r = 0; r < n; ++r) {
int i = e[r][0].second;
for (int lg = 29, y = x; lg >= 0; --lg) {
if (y >= (1 << lg)) {
y -= (1 << lg);
i = to[i][lg];
}
}
if (edges[i].first == p) ++ans;
}
answer(ans);
}
}
//
//int main() {
// int n, m, p;
// cin >> n >> m >> p;
// int r[m][2];
// for (int i = 0; i < m; ++i) {
// int u, v;
// cin >> u >> v;
// r[i][0] = u, r[i][1] = v;
// }
// int q;
// cin >> q;
// int g[q];
// for (int i = 0; i < q; ++i) cin >> g[i];
// count_routes(n, m, p, r, q, g);
//}
Compilation message
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:33:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
33 | auto [u, v] = edges[i];
| ^
garden.cpp:35:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
35 | for (auto [w, j]: e[v]) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7508 KB |
Output is correct |
2 |
Correct |
5 ms |
7536 KB |
Output is correct |
3 |
Correct |
5 ms |
7636 KB |
Output is correct |
4 |
Correct |
5 ms |
7360 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
6 ms |
7884 KB |
Output is correct |
7 |
Correct |
5 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7636 KB |
Output is correct |
9 |
Correct |
8 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7508 KB |
Output is correct |
2 |
Correct |
5 ms |
7536 KB |
Output is correct |
3 |
Correct |
5 ms |
7636 KB |
Output is correct |
4 |
Correct |
5 ms |
7360 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
6 ms |
7884 KB |
Output is correct |
7 |
Correct |
5 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7636 KB |
Output is correct |
9 |
Correct |
8 ms |
9684 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
11 |
Correct |
17 ms |
14228 KB |
Output is correct |
12 |
Correct |
65 ms |
23288 KB |
Output is correct |
13 |
Correct |
110 ms |
32968 KB |
Output is correct |
14 |
Correct |
176 ms |
51016 KB |
Output is correct |
15 |
Correct |
166 ms |
52888 KB |
Output is correct |
16 |
Correct |
167 ms |
48820 KB |
Output is correct |
17 |
Correct |
156 ms |
48596 KB |
Output is correct |
18 |
Correct |
50 ms |
23240 KB |
Output is correct |
19 |
Correct |
170 ms |
50996 KB |
Output is correct |
20 |
Correct |
179 ms |
52884 KB |
Output is correct |
21 |
Correct |
175 ms |
48800 KB |
Output is correct |
22 |
Correct |
152 ms |
48408 KB |
Output is correct |
23 |
Correct |
204 ms |
53580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7508 KB |
Output is correct |
2 |
Correct |
5 ms |
7536 KB |
Output is correct |
3 |
Correct |
5 ms |
7636 KB |
Output is correct |
4 |
Correct |
5 ms |
7360 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
6 ms |
7884 KB |
Output is correct |
7 |
Correct |
5 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7636 KB |
Output is correct |
9 |
Correct |
8 ms |
9684 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
11 |
Correct |
17 ms |
14228 KB |
Output is correct |
12 |
Correct |
65 ms |
23288 KB |
Output is correct |
13 |
Correct |
110 ms |
32968 KB |
Output is correct |
14 |
Correct |
176 ms |
51016 KB |
Output is correct |
15 |
Correct |
166 ms |
52888 KB |
Output is correct |
16 |
Correct |
167 ms |
48820 KB |
Output is correct |
17 |
Correct |
156 ms |
48596 KB |
Output is correct |
18 |
Correct |
50 ms |
23240 KB |
Output is correct |
19 |
Correct |
170 ms |
50996 KB |
Output is correct |
20 |
Correct |
179 ms |
52884 KB |
Output is correct |
21 |
Correct |
175 ms |
48800 KB |
Output is correct |
22 |
Correct |
152 ms |
48408 KB |
Output is correct |
23 |
Correct |
204 ms |
53580 KB |
Output is correct |
24 |
Correct |
10 ms |
7376 KB |
Output is correct |
25 |
Correct |
3141 ms |
14236 KB |
Output is correct |
26 |
Execution timed out |
5061 ms |
23356 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |