#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
bool line = 1;
bool binary = 1;
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) {
vector<int> ans(n);
iota(ans.begin(), ans.end(), 0);
return ans;
}
return {};
}
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) {
int ls = 31 - __builtin_clz(s+1), lt = 31 - __builtin_clz(t+1);
if (ls > lt) {
for (int x : c) if (x < s) return x;
assert(0);
}
else {
for (int x : c) if (x > s) {
bool F = 0;
for (int tmp = t+1; tmp; tmp /= 2) {
if (tmp == x+1) {
F = 1;
break;
}
}
if (F) return x;
}
for (int x : c) if (x < s) return x;
assert(0);
}
}
assert(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
317 ms |
684 KB |
Output is correct |
2 |
Correct |
296 ms |
684 KB |
Output is correct |
3 |
Correct |
463 ms |
684 KB |
Output is correct |
4 |
Correct |
346 ms |
684 KB |
Output is correct |
5 |
Correct |
333 ms |
684 KB |
Output is correct |
6 |
Correct |
248 ms |
684 KB |
Output is correct |
7 |
Correct |
256 ms |
684 KB |
Output is correct |
8 |
Correct |
0 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
249 ms |
684 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
288 ms |
684 KB |
Output is correct |
2 |
Correct |
241 ms |
688 KB |
Output is correct |
3 |
Correct |
513 ms |
684 KB |
Output is correct |
4 |
Correct |
385 ms |
696 KB |
Output is correct |
5 |
Correct |
351 ms |
680 KB |
Output is correct |
6 |
Correct |
259 ms |
684 KB |
Output is correct |
7 |
Correct |
228 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Incorrect |
0 ms |
432 KB |
Invalid length of array as the response of 'label'. scenario=1, n=4, len=0 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
490 ms |
684 KB |
Output is correct |
2 |
Correct |
396 ms |
684 KB |
Output is correct |
3 |
Correct |
309 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
776 KB |
Output is correct |
5 |
Correct |
1 ms |
776 KB |
Output is correct |
6 |
Correct |
0 ms |
764 KB |
Output is correct |
7 |
Incorrect |
0 ms |
344 KB |
Invalid length of array as the response of 'label'. scenario=0, n=4, len=0 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
304 ms |
688 KB |
Output is correct |
2 |
Correct |
230 ms |
684 KB |
Output is correct |
3 |
Correct |
515 ms |
940 KB |
Output is correct |
4 |
Correct |
323 ms |
684 KB |
Output is correct |
5 |
Correct |
303 ms |
684 KB |
Output is correct |
6 |
Correct |
244 ms |
684 KB |
Output is correct |
7 |
Correct |
247 ms |
684 KB |
Output is correct |
8 |
Correct |
0 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
776 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Incorrect |
270 ms |
764 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |