#include "stations.h"
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
void dfs(int cur, int ant, int & dtime, int h, vector<int> &labels, vector<vector<int> > & adj) {
if (h%2==0)
labels[cur]=dtime++;
for (int ni: adj[cur]) {
if (ni==ant)continue;
dfs(ni, cur, dtime, h+1, labels, adj);
}
if (h%2==1) {
labels[cur]=dtime++;
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
for (int i = 0; i < n; i++) {
labels[i] = i;
}
int d =0;
vector<vector<int> > adj(n);
for (int i =0; i < u.size(); i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0,0, d, 0, labels, adj);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(c.begin(), c.end());
//cout << "("<<s<<","<<t<<")";
for (int i =0; i < c.size(); i++) {
if (c[i]==t)return t;
}
if (s==0) {
int prev=0;
for (int i=0; i < c.size(); i++) {
if (prev <= t && t <= c[i])
return c[i];
prev=c[i];
}
return -1;
}
if (c[0] < s) {
if (t < c[0] || t > s)return c[0];
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 -2;
} else {
if(t<s||t>c[c.size()-1]) return c[c.size()-1];
int prev=s;
for (int i = 0; i < c.size(); i++) {
if (prev<= t && t <= c[i])return c[i];
prev=c[i];
}
return -3;
}
}
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i =0; i < u.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i =0; i < c.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp:45:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int i=0; i < c.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int i = 0; i < c.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
538 ms |
1024 KB |
Output is correct |
2 |
Correct |
511 ms |
1024 KB |
Output is correct |
3 |
Correct |
911 ms |
640 KB |
Output is correct |
4 |
Correct |
743 ms |
896 KB |
Output is correct |
5 |
Correct |
668 ms |
648 KB |
Output is correct |
6 |
Correct |
556 ms |
1024 KB |
Output is correct |
7 |
Correct |
463 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
800 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
492 ms |
752 KB |
Output is correct |
2 |
Correct |
582 ms |
836 KB |
Output is correct |
3 |
Correct |
1016 ms |
644 KB |
Output is correct |
4 |
Correct |
852 ms |
640 KB |
Output is correct |
5 |
Correct |
749 ms |
648 KB |
Output is correct |
6 |
Correct |
461 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
594 ms |
1024 KB |
Output is correct |
2 |
Correct |
495 ms |
1024 KB |
Output is correct |
3 |
Correct |
893 ms |
640 KB |
Output is correct |
4 |
Correct |
644 ms |
640 KB |
Output is correct |
5 |
Correct |
689 ms |
784 KB |
Output is correct |
6 |
Correct |
548 ms |
1024 KB |
Output is correct |
7 |
Correct |
534 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
648 KB |
Output is correct |
9 |
Correct |
5 ms |
648 KB |
Output is correct |
10 |
Correct |
2 ms |
672 KB |
Output is correct |
11 |
Correct |
688 ms |
648 KB |
Output is correct |
12 |
Correct |
459 ms |
1024 KB |
Output is correct |
13 |
Correct |
483 ms |
1024 KB |
Output is correct |
14 |
Correct |
462 ms |
832 KB |
Output is correct |
15 |
Correct |
77 ms |
640 KB |
Output is correct |
16 |
Correct |
90 ms |
996 KB |
Output is correct |
17 |
Correct |
141 ms |
816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
911 ms |
768 KB |
Output is correct |
2 |
Correct |
828 ms |
640 KB |
Output is correct |
3 |
Correct |
677 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
908 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
695 ms |
752 KB |
Output is correct |
8 |
Correct |
912 ms |
640 KB |
Output is correct |
9 |
Correct |
676 ms |
648 KB |
Output is correct |
10 |
Correct |
622 ms |
640 KB |
Output is correct |
11 |
Correct |
8 ms |
640 KB |
Output is correct |
12 |
Correct |
8 ms |
640 KB |
Output is correct |
13 |
Correct |
7 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
652 KB |
Output is correct |
15 |
Correct |
4 ms |
652 KB |
Output is correct |
16 |
Correct |
524 ms |
640 KB |
Output is correct |
17 |
Correct |
549 ms |
768 KB |
Output is correct |
18 |
Correct |
564 ms |
644 KB |
Output is correct |
19 |
Correct |
599 ms |
648 KB |
Output is correct |
20 |
Correct |
544 ms |
776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
708 ms |
1024 KB |
Output is correct |
2 |
Correct |
473 ms |
1024 KB |
Output is correct |
3 |
Correct |
1029 ms |
760 KB |
Output is correct |
4 |
Correct |
683 ms |
648 KB |
Output is correct |
5 |
Correct |
590 ms |
640 KB |
Output is correct |
6 |
Correct |
468 ms |
1024 KB |
Output is correct |
7 |
Correct |
510 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
467 ms |
780 KB |
Output is correct |
12 |
Correct |
662 ms |
816 KB |
Output is correct |
13 |
Correct |
1049 ms |
644 KB |
Output is correct |
14 |
Correct |
797 ms |
640 KB |
Output is correct |
15 |
Correct |
603 ms |
640 KB |
Output is correct |
16 |
Correct |
493 ms |
828 KB |
Output is correct |
17 |
Correct |
609 ms |
640 KB |
Output is correct |
18 |
Correct |
508 ms |
768 KB |
Output is correct |
19 |
Correct |
460 ms |
1024 KB |
Output is correct |
20 |
Correct |
445 ms |
760 KB |
Output is correct |
21 |
Correct |
68 ms |
1028 KB |
Output is correct |
22 |
Correct |
72 ms |
768 KB |
Output is correct |
23 |
Correct |
112 ms |
768 KB |
Output is correct |
24 |
Correct |
6 ms |
904 KB |
Output is correct |
25 |
Correct |
6 ms |
780 KB |
Output is correct |
26 |
Correct |
6 ms |
640 KB |
Output is correct |
27 |
Correct |
5 ms |
832 KB |
Output is correct |
28 |
Correct |
2 ms |
644 KB |
Output is correct |
29 |
Correct |
530 ms |
640 KB |
Output is correct |
30 |
Correct |
572 ms |
640 KB |
Output is correct |
31 |
Correct |
561 ms |
640 KB |
Output is correct |
32 |
Correct |
608 ms |
652 KB |
Output is correct |
33 |
Correct |
555 ms |
640 KB |
Output is correct |
34 |
Correct |
338 ms |
1024 KB |
Output is correct |
35 |
Correct |
569 ms |
1108 KB |
Output is correct |
36 |
Correct |
462 ms |
1024 KB |
Output is correct |
37 |
Correct |
460 ms |
800 KB |
Output is correct |
38 |
Correct |
604 ms |
768 KB |
Output is correct |
39 |
Correct |
527 ms |
788 KB |
Output is correct |
40 |
Correct |
546 ms |
796 KB |
Output is correct |
41 |
Correct |
519 ms |
948 KB |
Output is correct |
42 |
Correct |
66 ms |
848 KB |
Output is correct |
43 |
Correct |
100 ms |
824 KB |
Output is correct |
44 |
Correct |
177 ms |
832 KB |
Output is correct |
45 |
Correct |
183 ms |
768 KB |
Output is correct |
46 |
Correct |
340 ms |
828 KB |
Output is correct |
47 |
Correct |
424 ms |
784 KB |
Output is correct |
48 |
Correct |
84 ms |
828 KB |
Output is correct |
49 |
Correct |
71 ms |
768 KB |
Output is correct |