/**
* author: wxhtzdy
* created: 03.07.2022 18:28:39
**/
#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 k[]) {
vector<vector<pair<int, int>>> e(n);
for (int i = 0; i < m; i++) {
if ((int) e[r[i][0]].size() < 2) {
e[r[i][0]].emplace_back(i, r[i][1]);
}
if ((int) e[r[i][1]].size() < 2) {
e[r[i][1]].emplace_back(i, r[i][0]);
}
}
for (int i = 0; i < n; i++) {
if ((int) e[i].size() == 1) {
e[i].push_back(e[i][0]);
}
assert((int) e[i].size() == 2);
}
vector<vector<int>> g(2 * n);
function<void(int, int)> Add = [&](int v, int u) {
g[v].push_back(u);
};
for (int i = 0; i < n; i++) {
if (e[i][0].first == e[e[i][0].second][0].first) {
Add(i * 2, e[i][0].second * 2 + 1);
} else {
Add(i * 2, e[i][0].second * 2);
}
if (e[i][1].first == e[e[i][1].second][0].first) {
Add(i * 2 + 1, e[i][1].second * 2 + 1);
} else {
Add(i * 2 + 1, e[i][1].second * 2);
}
}
const int L = 32;
vector<vector<int>> jump(2 * n, vector<int>(L));
for (int i = 0; i < 2 * n; i++) {
jump[i][0] = g[i][0];
}
for (int j = 1; j < L; j++) {
for (int i = 0; i < 2 * n; i++) {
jump[i][j] = jump[jump[i][j - 1]][j - 1];
}
}
for (int i = 0; i < q; i++) {
int cnt = 0;
for (int j = 0; j < n; j++) {
int x = j * 2;
for (int l = L - 1; l >= 0; l--) {
if (k[i] >> l & 1) {
x = jump[x][l];
}
}
if (x == p * 2 || x == 2 * p + 1) {
cnt += 1;
}
}
answer(cnt);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
696 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
828 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
696 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
828 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
30 ms |
11836 KB |
Output is correct |
12 |
Correct |
62 ms |
19708 KB |
Output is correct |
13 |
Correct |
205 ms |
43976 KB |
Output is correct |
14 |
Correct |
240 ms |
69560 KB |
Output is correct |
15 |
Correct |
245 ms |
70516 KB |
Output is correct |
16 |
Correct |
173 ms |
48052 KB |
Output is correct |
17 |
Correct |
150 ms |
40644 KB |
Output is correct |
18 |
Correct |
60 ms |
19788 KB |
Output is correct |
19 |
Correct |
229 ms |
69756 KB |
Output is correct |
20 |
Correct |
240 ms |
70528 KB |
Output is correct |
21 |
Correct |
178 ms |
48056 KB |
Output is correct |
22 |
Correct |
140 ms |
40648 KB |
Output is correct |
23 |
Correct |
271 ms |
77224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
696 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
828 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
30 ms |
11836 KB |
Output is correct |
12 |
Correct |
62 ms |
19708 KB |
Output is correct |
13 |
Correct |
205 ms |
43976 KB |
Output is correct |
14 |
Correct |
240 ms |
69560 KB |
Output is correct |
15 |
Correct |
245 ms |
70516 KB |
Output is correct |
16 |
Correct |
173 ms |
48052 KB |
Output is correct |
17 |
Correct |
150 ms |
40644 KB |
Output is correct |
18 |
Correct |
60 ms |
19788 KB |
Output is correct |
19 |
Correct |
229 ms |
69756 KB |
Output is correct |
20 |
Correct |
240 ms |
70528 KB |
Output is correct |
21 |
Correct |
178 ms |
48056 KB |
Output is correct |
22 |
Correct |
140 ms |
40648 KB |
Output is correct |
23 |
Correct |
271 ms |
77224 KB |
Output is correct |
24 |
Correct |
11 ms |
372 KB |
Output is correct |
25 |
Execution timed out |
5083 ms |
11860 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |