#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
int timer = 0;
int st[1005], ed[1005], dep[1005];
vector<int> edg[1005];
vector<int> ans;
vector< pair<int,int> > tmp;
void dfs(int x, int p) {
if(x==0) dep[x] = 0;
else dep[x] = dep[p]+1;
st[x] = ++timer;
for(int i:edg[x]) {
if(i!=p) {
dfs(i, x);
}
}
ed[x] = ++timer;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
for(int i=0; i<n; i++) edg[i].clear();
for(int i=0; i<n-1; i++) {
edg[u[i]].push_back(v[i]);
edg[v[i]].push_back(u[i]);
}
dfs(0, -1);
ans.resize(n);
tmp.clear();
for(int i=0; i<n; i++) {
if(dep[i]%2==0) ans[i] = st[i];
else ans[i] = ed[i];
tmp.push_back({ans[i], i});
}
sort(tmp.begin(), tmp.end());
for(int i=0; i<n; i++) {
ans[tmp[i].second] = i;
}
return ans;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s == 0) {
sort(c.begin(), c.end());
for(int i=0; i<c.size(); i++) if(c[i]>=t) return c[i];
} else if(c[0] > s) { // s uses start time
sort(c.begin(), c.end());
if(t < s || t >= c[c.size()-1]) return c[c.size()-1];
for(int i=0; i<c.size()-1; i++) if(c[i]>=t) return c[i];
} else if(c[0] < s) { // s uses end time
sort(c.begin(), c.end());
if(t > s || c.size()==1 || t < c[1]) return c[0];
for(int i=1; i<c.size(); i++) if(i==c.size()-1 || t<c[i+1]) return c[i];
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=0; i<c.size(); i++) if(c[i]>=t) return c[i];
| ~^~~~~~~~~
stations.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i=0; i<c.size()-1; i++) if(c[i]>=t) return c[i];
| ~^~~~~~~~~~~
stations.cpp:55:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=1; i<c.size(); i++) if(i==c.size()-1 || t<c[i+1]) return c[i];
| ~^~~~~~~~~
stations.cpp:55:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=1; i<c.size(); i++) if(i==c.size()-1 || t<c[i+1]) return c[i];
| ~^~~~~~~~~~~~
stations.cpp:57:1: warning: control reaches end of non-void function [-Wreturn-type]
57 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
462 ms |
532 KB |
Output is correct |
2 |
Correct |
443 ms |
652 KB |
Output is correct |
3 |
Correct |
864 ms |
516 KB |
Output is correct |
4 |
Correct |
714 ms |
528 KB |
Output is correct |
5 |
Correct |
390 ms |
508 KB |
Output is correct |
6 |
Correct |
477 ms |
536 KB |
Output is correct |
7 |
Correct |
446 ms |
508 KB |
Output is correct |
8 |
Correct |
2 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
488 ms |
532 KB |
Output is correct |
2 |
Correct |
617 ms |
512 KB |
Output is correct |
3 |
Correct |
779 ms |
504 KB |
Output is correct |
4 |
Correct |
569 ms |
504 KB |
Output is correct |
5 |
Correct |
601 ms |
504 KB |
Output is correct |
6 |
Correct |
401 ms |
496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
417 ms |
636 KB |
Output is correct |
2 |
Correct |
469 ms |
648 KB |
Output is correct |
3 |
Correct |
775 ms |
400 KB |
Output is correct |
4 |
Correct |
474 ms |
400 KB |
Output is correct |
5 |
Correct |
466 ms |
516 KB |
Output is correct |
6 |
Correct |
410 ms |
632 KB |
Output is correct |
7 |
Correct |
476 ms |
508 KB |
Output is correct |
8 |
Correct |
2 ms |
448 KB |
Output is correct |
9 |
Correct |
4 ms |
576 KB |
Output is correct |
10 |
Correct |
1 ms |
608 KB |
Output is correct |
11 |
Correct |
565 ms |
512 KB |
Output is correct |
12 |
Correct |
435 ms |
616 KB |
Output is correct |
13 |
Correct |
372 ms |
620 KB |
Output is correct |
14 |
Correct |
403 ms |
500 KB |
Output is correct |
15 |
Correct |
64 ms |
548 KB |
Output is correct |
16 |
Correct |
69 ms |
524 KB |
Output is correct |
17 |
Correct |
89 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
821 ms |
508 KB |
Output is correct |
2 |
Correct |
618 ms |
520 KB |
Output is correct |
3 |
Correct |
492 ms |
516 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
5 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
589 ms |
492 KB |
Output is correct |
8 |
Correct |
913 ms |
508 KB |
Output is correct |
9 |
Correct |
611 ms |
400 KB |
Output is correct |
10 |
Correct |
566 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
4 ms |
476 KB |
Output is correct |
13 |
Correct |
3 ms |
464 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
540 ms |
492 KB |
Output is correct |
17 |
Correct |
375 ms |
636 KB |
Output is correct |
18 |
Correct |
492 ms |
508 KB |
Output is correct |
19 |
Correct |
514 ms |
528 KB |
Output is correct |
20 |
Correct |
519 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
472 ms |
652 KB |
Output is correct |
2 |
Correct |
492 ms |
520 KB |
Output is correct |
3 |
Correct |
877 ms |
504 KB |
Output is correct |
4 |
Correct |
572 ms |
500 KB |
Output is correct |
5 |
Correct |
552 ms |
504 KB |
Output is correct |
6 |
Correct |
349 ms |
508 KB |
Output is correct |
7 |
Correct |
435 ms |
500 KB |
Output is correct |
8 |
Correct |
1 ms |
576 KB |
Output is correct |
9 |
Correct |
4 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
596 KB |
Output is correct |
11 |
Correct |
525 ms |
504 KB |
Output is correct |
12 |
Correct |
504 ms |
652 KB |
Output is correct |
13 |
Correct |
912 ms |
492 KB |
Output is correct |
14 |
Correct |
669 ms |
504 KB |
Output is correct |
15 |
Correct |
546 ms |
520 KB |
Output is correct |
16 |
Correct |
415 ms |
508 KB |
Output is correct |
17 |
Correct |
614 ms |
504 KB |
Output is correct |
18 |
Correct |
365 ms |
620 KB |
Output is correct |
19 |
Correct |
451 ms |
724 KB |
Output is correct |
20 |
Correct |
479 ms |
520 KB |
Output is correct |
21 |
Correct |
66 ms |
528 KB |
Output is correct |
22 |
Correct |
61 ms |
528 KB |
Output is correct |
23 |
Correct |
112 ms |
520 KB |
Output is correct |
24 |
Correct |
8 ms |
508 KB |
Output is correct |
25 |
Correct |
4 ms |
468 KB |
Output is correct |
26 |
Correct |
4 ms |
596 KB |
Output is correct |
27 |
Correct |
4 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
476 KB |
Output is correct |
29 |
Correct |
529 ms |
488 KB |
Output is correct |
30 |
Correct |
484 ms |
496 KB |
Output is correct |
31 |
Correct |
454 ms |
528 KB |
Output is correct |
32 |
Correct |
449 ms |
404 KB |
Output is correct |
33 |
Correct |
442 ms |
512 KB |
Output is correct |
34 |
Correct |
291 ms |
652 KB |
Output is correct |
35 |
Correct |
429 ms |
732 KB |
Output is correct |
36 |
Correct |
446 ms |
736 KB |
Output is correct |
37 |
Correct |
411 ms |
736 KB |
Output is correct |
38 |
Correct |
500 ms |
724 KB |
Output is correct |
39 |
Correct |
405 ms |
632 KB |
Output is correct |
40 |
Correct |
393 ms |
644 KB |
Output is correct |
41 |
Correct |
467 ms |
620 KB |
Output is correct |
42 |
Correct |
50 ms |
700 KB |
Output is correct |
43 |
Correct |
122 ms |
744 KB |
Output is correct |
44 |
Correct |
125 ms |
528 KB |
Output is correct |
45 |
Correct |
151 ms |
508 KB |
Output is correct |
46 |
Correct |
303 ms |
528 KB |
Output is correct |
47 |
Correct |
239 ms |
524 KB |
Output is correct |
48 |
Correct |
67 ms |
836 KB |
Output is correct |
49 |
Correct |
65 ms |
784 KB |
Output is correct |