/**
* 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 = m - 1; i >= 0; 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]);
}
}
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].first][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].first][0].first) {
Add(i * 2 + 1, e[i][0].second * 2 + 1);
} else {
Add(i * 2 + 1, e[i][1].second * 2);
}
}
const int L = 32;
vector<vector<int>> jump(n, vector<int>(L));
for (int i = 0; i < n; i++) {
jump[i][0] = g[i * 2][0];
}
for (int j = 1; j < L; j++) {
for (int i = 0; i < 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;
for (int l = L - 1; l >= 0; l--) {
if (k[i] >> l & 1) {
x = jump[x][l];
}
}
if (x == p) {
cnt += 1;
}
}
answer(cnt);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
852 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
852 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
852 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |