// Problem: B - Speedrun
// Contest: Virtual Judge - PES segundo examen de práctica febrero 2024
// URL: https://vjudge.net/contest/612265#problem/B
// Memory Limit: 512 MB
// Time Limit: 3500 ms
// Start: 25-02-2024 15:56:28
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define gcd(x, y) __gcd(x, y)
#define mcm(x, y) abs((x) * (y)) / gcd(x, y)
#define all(x) begin(x), end(x)
#define pb(x) push_back(x)
#define endl '\n'
#ifdef DEBUG
int A[] = {0, 1, 2, 3, 3}, B[] = {0, 2, 3, 4, 5};
int N = 5;
int start = 1;
ll LEN;
bool hints[500][500] = {{}};
ll currNode = start;
void setHintLen(int l) { LEN = l; };
void setHint(int i, int j, bool b) { hints[i][j] = b; };
int getLength() { return LEN; };
bool getHint(int j) { return hints[currNode][j]; };
bool goTo(int x) {
for (int i = 1; i < N; i++) {
ll a = A[i], b = B[i];
if ((a == currNode && b == x) || (a == x && b == currNode)) {
currNode = x;
cout << currNode << ' ';
return true;
}
}
return false;
};
#else
void setHintLen(int l);
void setHint(int i, int j, bool b);
int getLength();
bool getHint(int j);
bool goTo(int x);
#endif
void assignHints(int subtask, int N, int A[], int B[]) {
if (subtask != 1) return;
setHintLen(N);
vector<vector<ll>> g(N + 1);
for (int i = 1; i < N; i++) {
g[A[i]].pb(B[i]);
g[B[i]].pb(A[i]);
}
for (int i = 1; i <= N; i++)
for (ll& nei : g[i]) setHint(i, nei, true);
}
void dfs(ll idx, ll p, ll N) {
for (int i = 1; i <= N; i++) {
bool x = getHint(i);
if (!x || i == p) continue;
goTo(i);
dfs(i, idx, N);
}
if (p != -1) goTo(p);
}
void speedrun(int subtask, int N, int start) {
if (subtask != 1) return;
dfs(start, -1, N);
}
#ifdef DEBUG
int main() {
cout << start << ' ';
assignHints(1, N, A, B);
speedrun(1, N, start);
cout << currNode;
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2188 KB |
Output is correct |
2 |
Correct |
22 ms |
1804 KB |
Output is correct |
3 |
Correct |
27 ms |
1628 KB |
Output is correct |
4 |
Correct |
22 ms |
1840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
setHintLen was never called |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
setHintLen was never called |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
setHintLen was never called |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
368 KB |
setHintLen was never called |
2 |
Halted |
0 ms |
0 KB |
- |