#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
typedef pair <int, int> pii;
vector <int> label(int N, int K, vector <int> u, vector <int> v) {
vector <vector <int>> adj(N);
for (int i = 0; i < N - 1; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
int timer = 0;
vector <pii> sorted;
vector <int> labels(N);
function <void(int, int, int)> dfs = [&](int x, int p, int d) {
int disc = timer++;
for (auto it : adj[x])
if (it != p)
dfs(it, x, d ^ 1);
int fin = timer++;
sorted.push_back({d ? fin : disc, x});
};
dfs(0, -1, 0);
sort(sorted.begin(), sorted.end());
for (int i = 0; i < N; i++)
labels[sorted[i].second] = i;
return labels;
}
int find_next_station(int start, int dest, vector <int> neigh) {
if (start < neigh[0]) {
int parent = neigh.back();
neigh.insert(neigh.begin(), start);
if (start)
neigh.pop_back();
for (int i = 1; i < neigh.size(); i++)
if (dest > neigh[i - 1] && dest <= neigh[i])
return neigh[i];
return parent;
}
else {
int parent = neigh[0];
neigh.erase(neigh.begin());
neigh.push_back(start);
for (int i = 1; i < neigh.size(); i++)
if (dest >= neigh[i - 1] && dest < neigh[i])
return neigh[i - 1];
return parent;
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 1; i < neigh.size(); i++)
| ~~^~~~~~~~~~~~~~
stations.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i = 1; i < neigh.size(); i++)
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
627 ms |
1024 KB |
Output is correct |
2 |
Correct |
616 ms |
1080 KB |
Output is correct |
3 |
Correct |
887 ms |
768 KB |
Output is correct |
4 |
Correct |
798 ms |
640 KB |
Output is correct |
5 |
Correct |
682 ms |
648 KB |
Output is correct |
6 |
Correct |
526 ms |
984 KB |
Output is correct |
7 |
Correct |
584 ms |
1008 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
6 ms |
876 KB |
Output is correct |
10 |
Correct |
2 ms |
1032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
454 ms |
760 KB |
Output is correct |
2 |
Correct |
587 ms |
760 KB |
Output is correct |
3 |
Correct |
980 ms |
652 KB |
Output is correct |
4 |
Correct |
726 ms |
748 KB |
Output is correct |
5 |
Correct |
660 ms |
768 KB |
Output is correct |
6 |
Correct |
486 ms |
940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
606 ms |
1024 KB |
Output is correct |
2 |
Correct |
532 ms |
1024 KB |
Output is correct |
3 |
Correct |
1027 ms |
640 KB |
Output is correct |
4 |
Correct |
697 ms |
640 KB |
Output is correct |
5 |
Correct |
648 ms |
640 KB |
Output is correct |
6 |
Correct |
548 ms |
1024 KB |
Output is correct |
7 |
Correct |
542 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
648 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
587 ms |
752 KB |
Output is correct |
12 |
Correct |
498 ms |
1024 KB |
Output is correct |
13 |
Correct |
494 ms |
1008 KB |
Output is correct |
14 |
Correct |
540 ms |
804 KB |
Output is correct |
15 |
Correct |
56 ms |
900 KB |
Output is correct |
16 |
Correct |
66 ms |
932 KB |
Output is correct |
17 |
Correct |
110 ms |
800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
887 ms |
780 KB |
Output is correct |
2 |
Correct |
703 ms |
648 KB |
Output is correct |
3 |
Correct |
661 ms |
640 KB |
Output is correct |
4 |
Correct |
1 ms |
648 KB |
Output is correct |
5 |
Correct |
4 ms |
648 KB |
Output is correct |
6 |
Correct |
1 ms |
656 KB |
Output is correct |
7 |
Correct |
690 ms |
784 KB |
Output is correct |
8 |
Correct |
1049 ms |
648 KB |
Output is correct |
9 |
Correct |
758 ms |
640 KB |
Output is correct |
10 |
Correct |
590 ms |
644 KB |
Output is correct |
11 |
Correct |
6 ms |
644 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
3 ms |
644 KB |
Output is correct |
15 |
Correct |
1 ms |
652 KB |
Output is correct |
16 |
Correct |
505 ms |
776 KB |
Output is correct |
17 |
Correct |
504 ms |
640 KB |
Output is correct |
18 |
Correct |
471 ms |
640 KB |
Output is correct |
19 |
Correct |
494 ms |
788 KB |
Output is correct |
20 |
Correct |
490 ms |
644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
518 ms |
1024 KB |
Output is correct |
2 |
Correct |
439 ms |
1024 KB |
Output is correct |
3 |
Correct |
848 ms |
652 KB |
Output is correct |
4 |
Correct |
643 ms |
648 KB |
Output is correct |
5 |
Correct |
576 ms |
648 KB |
Output is correct |
6 |
Correct |
429 ms |
1024 KB |
Output is correct |
7 |
Correct |
423 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
4 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
644 KB |
Output is correct |
11 |
Correct |
452 ms |
768 KB |
Output is correct |
12 |
Correct |
504 ms |
808 KB |
Output is correct |
13 |
Correct |
848 ms |
648 KB |
Output is correct |
14 |
Correct |
669 ms |
640 KB |
Output is correct |
15 |
Correct |
604 ms |
648 KB |
Output is correct |
16 |
Correct |
428 ms |
816 KB |
Output is correct |
17 |
Correct |
611 ms |
644 KB |
Output is correct |
18 |
Correct |
470 ms |
1120 KB |
Output is correct |
19 |
Correct |
458 ms |
1008 KB |
Output is correct |
20 |
Correct |
501 ms |
812 KB |
Output is correct |
21 |
Correct |
60 ms |
768 KB |
Output is correct |
22 |
Correct |
91 ms |
768 KB |
Output is correct |
23 |
Correct |
143 ms |
768 KB |
Output is correct |
24 |
Correct |
7 ms |
640 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
6 ms |
644 KB |
Output is correct |
27 |
Correct |
3 ms |
656 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
29 |
Correct |
617 ms |
784 KB |
Output is correct |
30 |
Correct |
545 ms |
640 KB |
Output is correct |
31 |
Correct |
537 ms |
648 KB |
Output is correct |
32 |
Correct |
534 ms |
640 KB |
Output is correct |
33 |
Correct |
530 ms |
640 KB |
Output is correct |
34 |
Correct |
338 ms |
1280 KB |
Output is correct |
35 |
Correct |
460 ms |
1024 KB |
Output is correct |
36 |
Correct |
585 ms |
1008 KB |
Output is correct |
37 |
Correct |
612 ms |
948 KB |
Output is correct |
38 |
Correct |
542 ms |
904 KB |
Output is correct |
39 |
Correct |
541 ms |
768 KB |
Output is correct |
40 |
Correct |
487 ms |
780 KB |
Output is correct |
41 |
Correct |
588 ms |
784 KB |
Output is correct |
42 |
Correct |
73 ms |
952 KB |
Output is correct |
43 |
Correct |
147 ms |
808 KB |
Output is correct |
44 |
Correct |
153 ms |
808 KB |
Output is correct |
45 |
Correct |
160 ms |
928 KB |
Output is correct |
46 |
Correct |
339 ms |
796 KB |
Output is correct |
47 |
Correct |
391 ms |
1024 KB |
Output is correct |
48 |
Correct |
82 ms |
808 KB |
Output is correct |
49 |
Correct |
78 ms |
804 KB |
Output is correct |