#include "stations.h"
#include "bits/stdc++.h"
using namespace std;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
vector<vector<int>> adj(n);
vector<bool> vis(n);
for (int i = 0; i < n - 1; i++) {
adj[u[i]].emplace_back(v[i]);
adj[v[i]].emplace_back(u[i]);
}
int z = 0;
vector<int> h(n), tin(n), tout(n), ans(n);
auto dfs = [&](auto &dfs, int u) -> void {
if (h[u] % 2 == 0) tin[u] = z++;
vis[u] = true;
for (int v: adj[u]) {
if (vis[v]) continue;
h[v] = h[u] + 1;
dfs(dfs, v);
}
if (h[u] % 2) tout[u] = z++;
};
dfs(dfs, 0);
for (int i = 0; i < n; i++) ans[i] = h[i] % 2 ? tout[i] : tin[i];
// for (int i = 0; i < n; i++) cout << ans[i] << ' ';
// cout << endl;
return ans;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(c.begin(), c.end());
// cout << '\t' << s << ' ' << t << endl;
// cout << '\t';
// for (int u: c) cout << u << ' ';
// cout << endl;
bool even = true;
for (int u: c) even &= u > s;
if (even) {
for (int u: c) {
if (s <= t and t <= u) return u;
}
return c.back();
} else {
reverse(c.begin(), c.end());
for (int u: c) {
if (u == c.back()) return u;
if (u <= t and t <= s) return u;
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
52 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
369 ms |
896 KB |
Output is correct |
2 |
Correct |
300 ms |
892 KB |
Output is correct |
3 |
Correct |
600 ms |
684 KB |
Output is correct |
4 |
Correct |
413 ms |
940 KB |
Output is correct |
5 |
Correct |
402 ms |
688 KB |
Output is correct |
6 |
Correct |
299 ms |
944 KB |
Output is correct |
7 |
Correct |
289 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
772 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
0 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
282 ms |
1112 KB |
Output is correct |
2 |
Correct |
355 ms |
792 KB |
Output is correct |
3 |
Correct |
540 ms |
684 KB |
Output is correct |
4 |
Correct |
504 ms |
684 KB |
Output is correct |
5 |
Correct |
354 ms |
684 KB |
Output is correct |
6 |
Correct |
295 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
348 ms |
896 KB |
Output is correct |
2 |
Correct |
308 ms |
900 KB |
Output is correct |
3 |
Correct |
588 ms |
684 KB |
Output is correct |
4 |
Correct |
421 ms |
684 KB |
Output is correct |
5 |
Correct |
374 ms |
684 KB |
Output is correct |
6 |
Correct |
294 ms |
884 KB |
Output is correct |
7 |
Correct |
282 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
764 KB |
Output is correct |
9 |
Correct |
2 ms |
760 KB |
Output is correct |
10 |
Correct |
1 ms |
764 KB |
Output is correct |
11 |
Correct |
371 ms |
684 KB |
Output is correct |
12 |
Correct |
314 ms |
948 KB |
Output is correct |
13 |
Correct |
304 ms |
1408 KB |
Output is correct |
14 |
Correct |
269 ms |
684 KB |
Output is correct |
15 |
Correct |
37 ms |
764 KB |
Output is correct |
16 |
Correct |
39 ms |
892 KB |
Output is correct |
17 |
Correct |
63 ms |
900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
556 ms |
688 KB |
Output is correct |
2 |
Correct |
431 ms |
696 KB |
Output is correct |
3 |
Correct |
374 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
764 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
0 ms |
768 KB |
Output is correct |
7 |
Correct |
383 ms |
684 KB |
Output is correct |
8 |
Correct |
603 ms |
684 KB |
Output is correct |
9 |
Correct |
396 ms |
936 KB |
Output is correct |
10 |
Correct |
392 ms |
684 KB |
Output is correct |
11 |
Correct |
3 ms |
768 KB |
Output is correct |
12 |
Correct |
3 ms |
768 KB |
Output is correct |
13 |
Correct |
2 ms |
772 KB |
Output is correct |
14 |
Correct |
3 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
327 ms |
684 KB |
Output is correct |
17 |
Correct |
350 ms |
684 KB |
Output is correct |
18 |
Correct |
351 ms |
684 KB |
Output is correct |
19 |
Correct |
359 ms |
684 KB |
Output is correct |
20 |
Correct |
327 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
349 ms |
896 KB |
Output is correct |
2 |
Correct |
303 ms |
1148 KB |
Output is correct |
3 |
Correct |
559 ms |
684 KB |
Output is correct |
4 |
Correct |
422 ms |
684 KB |
Output is correct |
5 |
Correct |
376 ms |
684 KB |
Output is correct |
6 |
Correct |
280 ms |
884 KB |
Output is correct |
7 |
Correct |
299 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
281 ms |
868 KB |
Output is correct |
12 |
Correct |
354 ms |
1080 KB |
Output is correct |
13 |
Correct |
590 ms |
940 KB |
Output is correct |
14 |
Correct |
438 ms |
684 KB |
Output is correct |
15 |
Correct |
397 ms |
684 KB |
Output is correct |
16 |
Correct |
292 ms |
684 KB |
Output is correct |
17 |
Correct |
394 ms |
684 KB |
Output is correct |
18 |
Correct |
297 ms |
1300 KB |
Output is correct |
19 |
Correct |
320 ms |
1228 KB |
Output is correct |
20 |
Correct |
273 ms |
684 KB |
Output is correct |
21 |
Correct |
37 ms |
868 KB |
Output is correct |
22 |
Correct |
42 ms |
884 KB |
Output is correct |
23 |
Correct |
66 ms |
860 KB |
Output is correct |
24 |
Correct |
4 ms |
768 KB |
Output is correct |
25 |
Correct |
4 ms |
768 KB |
Output is correct |
26 |
Correct |
2 ms |
764 KB |
Output is correct |
27 |
Correct |
3 ms |
772 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
293 ms |
684 KB |
Output is correct |
30 |
Correct |
311 ms |
684 KB |
Output is correct |
31 |
Correct |
378 ms |
688 KB |
Output is correct |
32 |
Correct |
337 ms |
684 KB |
Output is correct |
33 |
Correct |
316 ms |
684 KB |
Output is correct |
34 |
Correct |
186 ms |
892 KB |
Output is correct |
35 |
Correct |
260 ms |
960 KB |
Output is correct |
36 |
Correct |
284 ms |
1148 KB |
Output is correct |
37 |
Correct |
282 ms |
964 KB |
Output is correct |
38 |
Correct |
286 ms |
1124 KB |
Output is correct |
39 |
Correct |
288 ms |
1240 KB |
Output is correct |
40 |
Correct |
319 ms |
960 KB |
Output is correct |
41 |
Correct |
286 ms |
960 KB |
Output is correct |
42 |
Correct |
42 ms |
844 KB |
Output is correct |
43 |
Correct |
70 ms |
872 KB |
Output is correct |
44 |
Correct |
97 ms |
1116 KB |
Output is correct |
45 |
Correct |
116 ms |
872 KB |
Output is correct |
46 |
Correct |
197 ms |
852 KB |
Output is correct |
47 |
Correct |
186 ms |
1056 KB |
Output is correct |
48 |
Correct |
39 ms |
1380 KB |
Output is correct |
49 |
Correct |
40 ms |
1168 KB |
Output is correct |