#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
bool line = 1;
bool binary = 1;
const int N = 1001;
vector<vector<int>> go(N, vector<int>(N));
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
vector<vector<int>> adj(n);
for (int i = 0; i < n-1; i++) {
if (u[i] > v[i]) swap(u[i], v[i]);
binary &= (v[i] + 1) / 2 == (u[i] + 1);
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
int r = -1;
for (int i = 0; i < n; i++) {
if (adj[i].size() == 1) r = i;
line &= adj[i].size() <= 2;
}
if (line) {
vector<int> ans(n);
int t = 0;
auto dfs = [&](auto&& s, int v, int p) -> void {
ans[v] = t++;
for (int u : adj[v]) if (u != p) s(s, u, v);
};
dfs(dfs, r, -1);
return ans;
}
/*
if (binary) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) go[i][j] = -1;
auto dfs = [&](auto&& s, int v) -> void {
for (int u : adj[v]) if (u != go[i][v]) {
go[i][u] = v;
s(s, u);
}
};
dfs(dfs, i);
}
vector<int> ans(n);
iota(ans.begin(), ans.end(), 0);
return ans;
}
*/
vector<int> tin(n), tout(n);
int timer = 0;
auto dfs = [&](auto&& s, int v, int p) -> void {
tin[v] = timer++;
for (int u : adj[v]) if (u != p) {
s(s, u, v);
}
tout[v] = timer - 1;
};
dfs(dfs, 0, -1);
vector<int> ans(n);
for (int i = 0; i < n; i++) ans[i] = tin[i] * 1000 + tout[i];
return ans;
}
bool anc(int x, int y) {
int tins = x / 1000, touts = x % 1000;
int tint = y / 1000, toutt = y % 1000;
return tins <= tint && toutt <= touts;
}
int find_next_station(int s, int t, std::vector<int> c) {
if (line) {
for (int x : c) if ((x-s)*(x-t) <= 0) return x;
}
/*
if (binary) {
return go[t][s];
}
*/
if (anc(s, t)) {
for (int x : c) {
if (anc(s, x) && anc(x, t)) return x;
}
}
else {
for (int x : c) {
if (anc(x, s)) return x;
}
}
assert(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
274 ms |
8620 KB |
Output is correct |
2 |
Correct |
271 ms |
8620 KB |
Output is correct |
3 |
Correct |
530 ms |
8364 KB |
Output is correct |
4 |
Correct |
394 ms |
8364 KB |
Output is correct |
5 |
Correct |
338 ms |
8364 KB |
Output is correct |
6 |
Correct |
250 ms |
8620 KB |
Output is correct |
7 |
Correct |
254 ms |
8620 KB |
Output is correct |
8 |
Correct |
4 ms |
8448 KB |
Output is correct |
9 |
Correct |
5 ms |
8456 KB |
Output is correct |
10 |
Correct |
4 ms |
8468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4440 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1511 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
298 ms |
8620 KB |
Output is correct |
2 |
Correct |
256 ms |
8620 KB |
Output is correct |
3 |
Correct |
522 ms |
8364 KB |
Output is correct |
4 |
Correct |
399 ms |
8364 KB |
Output is correct |
5 |
Correct |
322 ms |
8364 KB |
Output is correct |
6 |
Correct |
253 ms |
8620 KB |
Output is correct |
7 |
Correct |
285 ms |
8620 KB |
Output is correct |
8 |
Correct |
4 ms |
8464 KB |
Output is correct |
9 |
Correct |
5 ms |
8456 KB |
Output is correct |
10 |
Correct |
4 ms |
8456 KB |
Output is correct |
11 |
Incorrect |
332 ms |
8572 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
470 ms |
8364 KB |
Output is correct |
2 |
Correct |
378 ms |
8364 KB |
Output is correct |
3 |
Correct |
340 ms |
8364 KB |
Output is correct |
4 |
Correct |
4 ms |
8452 KB |
Output is correct |
5 |
Correct |
5 ms |
8596 KB |
Output is correct |
6 |
Correct |
4 ms |
8464 KB |
Output is correct |
7 |
Incorrect |
327 ms |
8368 KB |
Wrong query response. |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
343 ms |
8620 KB |
Output is correct |
2 |
Correct |
235 ms |
8620 KB |
Output is correct |
3 |
Correct |
534 ms |
8616 KB |
Output is correct |
4 |
Correct |
402 ms |
8364 KB |
Output is correct |
5 |
Correct |
353 ms |
8364 KB |
Output is correct |
6 |
Correct |
253 ms |
8620 KB |
Output is correct |
7 |
Correct |
259 ms |
8620 KB |
Output is correct |
8 |
Correct |
4 ms |
8464 KB |
Output is correct |
9 |
Correct |
5 ms |
8460 KB |
Output is correct |
10 |
Correct |
4 ms |
8456 KB |
Output is correct |
11 |
Incorrect |
274 ms |
8620 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |