#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
int tmm = 0;
void dfs(int cur, int pr, vector<int>& tin, vector<int>& tout, vector<int>& d, vector<vector<int>>& ed) {
tin[cur] = tmm++;
d[cur] = d[pr] + 1;
for (auto to : ed[cur]) {
if (to == pr) continue;
dfs(to, cur, tin, tout, d, ed);
}
tout[cur] = tmm++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<vector<int>> ed(n);
for (int i = 0; i < n-1; ++i) {
ed[u[i]].push_back(v[i]);
ed[v[i]].push_back(u[i]);
}
vector<int> d(n), tin(n), tout(n);
tmm = 0, d[0] = -1;
dfs(0, 0, tin, tout, d, ed);
vector<int> label(n);
for (int i = 0; i < n; ++i){
if (d[i] % 2 == 0) label[i] = tin[i];
else label[i] = tout[i];
}
vector<pair<int, int>> arr;
for (int i = 0; i < n; ++i) arr.push_back({label[i], i});
int x = 0;
sort(arr.begin(), arr.end());
for (int i = 0; i < n; ++i) label[arr[i].second] = x++;
return label;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(), c.end());
if (s < c[0]){
int prev = s;
for (int i = 0; i < c.size() - 1; ++i){
if (prev <= t && t <= c[i]) return c[i];
prev = c[i];
}
return c.back();
} else{
int prev = s;
for (int i = c.size() - 1; i > 0; --i){
if (c[i] <= t && t <= prev) return c[i];
prev = c[i];
}
return c[0];
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < c.size() - 1; ++i){
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
562 ms |
676 KB |
Output is correct |
2 |
Correct |
470 ms |
620 KB |
Output is correct |
3 |
Correct |
869 ms |
420 KB |
Output is correct |
4 |
Correct |
697 ms |
484 KB |
Output is correct |
5 |
Correct |
590 ms |
420 KB |
Output is correct |
6 |
Correct |
439 ms |
676 KB |
Output is correct |
7 |
Correct |
430 ms |
676 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
439 ms |
504 KB |
Output is correct |
2 |
Correct |
569 ms |
548 KB |
Output is correct |
3 |
Correct |
778 ms |
500 KB |
Output is correct |
4 |
Correct |
602 ms |
416 KB |
Output is correct |
5 |
Correct |
484 ms |
416 KB |
Output is correct |
6 |
Correct |
433 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
583 ms |
676 KB |
Output is correct |
2 |
Correct |
442 ms |
632 KB |
Output is correct |
3 |
Correct |
789 ms |
500 KB |
Output is correct |
4 |
Correct |
657 ms |
420 KB |
Output is correct |
5 |
Correct |
644 ms |
420 KB |
Output is correct |
6 |
Correct |
500 ms |
628 KB |
Output is correct |
7 |
Correct |
477 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
570 ms |
500 KB |
Output is correct |
12 |
Correct |
502 ms |
760 KB |
Output is correct |
13 |
Correct |
456 ms |
748 KB |
Output is correct |
14 |
Correct |
413 ms |
548 KB |
Output is correct |
15 |
Correct |
47 ms |
492 KB |
Output is correct |
16 |
Correct |
65 ms |
620 KB |
Output is correct |
17 |
Correct |
97 ms |
548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
903 ms |
488 KB |
Output is correct |
2 |
Correct |
654 ms |
420 KB |
Output is correct |
3 |
Correct |
542 ms |
420 KB |
Output is correct |
4 |
Correct |
1 ms |
496 KB |
Output is correct |
5 |
Correct |
4 ms |
500 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
529 ms |
416 KB |
Output is correct |
8 |
Correct |
849 ms |
416 KB |
Output is correct |
9 |
Correct |
645 ms |
420 KB |
Output is correct |
10 |
Correct |
534 ms |
536 KB |
Output is correct |
11 |
Correct |
6 ms |
500 KB |
Output is correct |
12 |
Correct |
5 ms |
500 KB |
Output is correct |
13 |
Correct |
3 ms |
492 KB |
Output is correct |
14 |
Correct |
3 ms |
500 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
435 ms |
416 KB |
Output is correct |
17 |
Correct |
426 ms |
420 KB |
Output is correct |
18 |
Correct |
468 ms |
504 KB |
Output is correct |
19 |
Correct |
454 ms |
420 KB |
Output is correct |
20 |
Correct |
521 ms |
420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
526 ms |
636 KB |
Output is correct |
2 |
Correct |
390 ms |
640 KB |
Output is correct |
3 |
Correct |
851 ms |
416 KB |
Output is correct |
4 |
Correct |
614 ms |
512 KB |
Output is correct |
5 |
Correct |
550 ms |
420 KB |
Output is correct |
6 |
Correct |
379 ms |
676 KB |
Output is correct |
7 |
Correct |
362 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
488 KB |
Output is correct |
11 |
Correct |
457 ms |
616 KB |
Output is correct |
12 |
Correct |
515 ms |
548 KB |
Output is correct |
13 |
Correct |
861 ms |
416 KB |
Output is correct |
14 |
Correct |
669 ms |
420 KB |
Output is correct |
15 |
Correct |
550 ms |
420 KB |
Output is correct |
16 |
Correct |
478 ms |
676 KB |
Output is correct |
17 |
Correct |
583 ms |
416 KB |
Output is correct |
18 |
Correct |
421 ms |
876 KB |
Output is correct |
19 |
Correct |
346 ms |
628 KB |
Output is correct |
20 |
Correct |
409 ms |
500 KB |
Output is correct |
21 |
Correct |
58 ms |
492 KB |
Output is correct |
22 |
Correct |
66 ms |
504 KB |
Output is correct |
23 |
Correct |
101 ms |
544 KB |
Output is correct |
24 |
Correct |
5 ms |
500 KB |
Output is correct |
25 |
Correct |
5 ms |
488 KB |
Output is correct |
26 |
Correct |
5 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
528 ms |
508 KB |
Output is correct |
30 |
Correct |
502 ms |
420 KB |
Output is correct |
31 |
Correct |
464 ms |
444 KB |
Output is correct |
32 |
Correct |
466 ms |
508 KB |
Output is correct |
33 |
Correct |
415 ms |
508 KB |
Output is correct |
34 |
Correct |
292 ms |
544 KB |
Output is correct |
35 |
Correct |
365 ms |
632 KB |
Output is correct |
36 |
Correct |
430 ms |
632 KB |
Output is correct |
37 |
Correct |
434 ms |
712 KB |
Output is correct |
38 |
Correct |
453 ms |
748 KB |
Output is correct |
39 |
Correct |
400 ms |
628 KB |
Output is correct |
40 |
Correct |
420 ms |
752 KB |
Output is correct |
41 |
Correct |
456 ms |
712 KB |
Output is correct |
42 |
Correct |
54 ms |
576 KB |
Output is correct |
43 |
Correct |
105 ms |
568 KB |
Output is correct |
44 |
Correct |
139 ms |
636 KB |
Output is correct |
45 |
Correct |
162 ms |
508 KB |
Output is correct |
46 |
Correct |
285 ms |
612 KB |
Output is correct |
47 |
Correct |
321 ms |
740 KB |
Output is correct |
48 |
Correct |
66 ms |
660 KB |
Output is correct |
49 |
Correct |
59 ms |
648 KB |
Output is correct |