#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1005;
int pre[N], post[N], d[N];
vector<int> E[N];
int wsk=1;
void dfs(int v, int p){
//cout<<v<<" "<<p<<" "<<wsk<<endl;
pre[v]=wsk++;
for(int u:E[v]){
if(u!=p){
assert(pre[u]==0);
d[u]=d[v]+1;
dfs(u, v);
}
}
post[v]=wsk++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
for(int i=0; i<n; i++){
pre[i]=post[i]=d[i]=0;
E[i].clear();
}
for(int i=0; i<n-1; i++){
E[u[i]].push_back(v[i]);
E[v[i]].push_back(u[i]);
}
std::vector<int> labels(n);
wsk=1;
d[0]=0;
dfs(0, -1);
vector<pair<int, int > > V(n);
for (int i = 0; i < n; i++) {
if(d[i]&1)V[i] = {pre[i], i};
else V[i]={post[i], i};
//cout<<i<<" "<<labels[i]<<"\n";
}
sort(V.begin(), V.end());
for(int i=0; i<n; i++){
labels[V[i].second]=i;
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(c.begin(), c.end());
bool ma=1;
for(int i:c){
if(i>s)ma=0;
}
if(ma){
if(t>=s)return c[0];
for(int i=c.size()-1; i>=0; i--){
if(c[i]<=t)return c[i];
}
return c[0];
}
else{
//reverse(c.begin(), c.end());
if(t<s)return c.back();
for(int i=0; i<c.size(); i++){
if(c[i]>=t)return c[i];
}
return c.back();
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:62:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i=0; i<c.size(); i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
720 ms |
656 KB |
Output is correct |
2 |
Correct |
503 ms |
656 KB |
Output is correct |
3 |
Correct |
1035 ms |
492 KB |
Output is correct |
4 |
Correct |
691 ms |
400 KB |
Output is correct |
5 |
Correct |
529 ms |
528 KB |
Output is correct |
6 |
Correct |
571 ms |
624 KB |
Output is correct |
7 |
Correct |
613 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
476 KB |
Output is correct |
9 |
Correct |
5 ms |
728 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
604 ms |
528 KB |
Output is correct |
2 |
Correct |
692 ms |
524 KB |
Output is correct |
3 |
Correct |
985 ms |
508 KB |
Output is correct |
4 |
Correct |
916 ms |
492 KB |
Output is correct |
5 |
Correct |
668 ms |
528 KB |
Output is correct |
6 |
Correct |
493 ms |
656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
601 ms |
648 KB |
Output is correct |
2 |
Correct |
650 ms |
788 KB |
Output is correct |
3 |
Correct |
1178 ms |
528 KB |
Output is correct |
4 |
Correct |
775 ms |
588 KB |
Output is correct |
5 |
Correct |
763 ms |
644 KB |
Output is correct |
6 |
Correct |
514 ms |
636 KB |
Output is correct |
7 |
Correct |
506 ms |
648 KB |
Output is correct |
8 |
Correct |
3 ms |
728 KB |
Output is correct |
9 |
Correct |
6 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
797 ms |
528 KB |
Output is correct |
12 |
Correct |
561 ms |
772 KB |
Output is correct |
13 |
Correct |
540 ms |
528 KB |
Output is correct |
14 |
Correct |
564 ms |
656 KB |
Output is correct |
15 |
Correct |
69 ms |
724 KB |
Output is correct |
16 |
Correct |
88 ms |
656 KB |
Output is correct |
17 |
Correct |
142 ms |
656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
884 ms |
528 KB |
Output is correct |
2 |
Correct |
709 ms |
520 KB |
Output is correct |
3 |
Correct |
826 ms |
648 KB |
Output is correct |
4 |
Correct |
3 ms |
600 KB |
Output is correct |
5 |
Correct |
5 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
608 KB |
Output is correct |
7 |
Correct |
765 ms |
508 KB |
Output is correct |
8 |
Correct |
867 ms |
512 KB |
Output is correct |
9 |
Correct |
754 ms |
528 KB |
Output is correct |
10 |
Correct |
771 ms |
656 KB |
Output is correct |
11 |
Correct |
6 ms |
600 KB |
Output is correct |
12 |
Correct |
8 ms |
600 KB |
Output is correct |
13 |
Correct |
6 ms |
728 KB |
Output is correct |
14 |
Correct |
4 ms |
728 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
683 ms |
512 KB |
Output is correct |
17 |
Correct |
643 ms |
528 KB |
Output is correct |
18 |
Correct |
534 ms |
512 KB |
Output is correct |
19 |
Correct |
669 ms |
656 KB |
Output is correct |
20 |
Correct |
692 ms |
540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
585 ms |
632 KB |
Output is correct |
2 |
Correct |
506 ms |
528 KB |
Output is correct |
3 |
Correct |
1204 ms |
528 KB |
Output is correct |
4 |
Correct |
847 ms |
528 KB |
Output is correct |
5 |
Correct |
606 ms |
528 KB |
Output is correct |
6 |
Correct |
434 ms |
520 KB |
Output is correct |
7 |
Correct |
468 ms |
656 KB |
Output is correct |
8 |
Correct |
5 ms |
600 KB |
Output is correct |
9 |
Correct |
4 ms |
600 KB |
Output is correct |
10 |
Correct |
3 ms |
616 KB |
Output is correct |
11 |
Correct |
462 ms |
528 KB |
Output is correct |
12 |
Correct |
527 ms |
648 KB |
Output is correct |
13 |
Correct |
1022 ms |
528 KB |
Output is correct |
14 |
Correct |
801 ms |
528 KB |
Output is correct |
15 |
Correct |
569 ms |
516 KB |
Output is correct |
16 |
Correct |
584 ms |
672 KB |
Output is correct |
17 |
Correct |
675 ms |
452 KB |
Output is correct |
18 |
Correct |
566 ms |
760 KB |
Output is correct |
19 |
Correct |
499 ms |
628 KB |
Output is correct |
20 |
Correct |
614 ms |
536 KB |
Output is correct |
21 |
Correct |
73 ms |
656 KB |
Output is correct |
22 |
Correct |
94 ms |
656 KB |
Output is correct |
23 |
Correct |
148 ms |
672 KB |
Output is correct |
24 |
Correct |
5 ms |
600 KB |
Output is correct |
25 |
Correct |
6 ms |
728 KB |
Output is correct |
26 |
Correct |
6 ms |
600 KB |
Output is correct |
27 |
Correct |
5 ms |
728 KB |
Output is correct |
28 |
Correct |
2 ms |
600 KB |
Output is correct |
29 |
Correct |
635 ms |
512 KB |
Output is correct |
30 |
Correct |
625 ms |
656 KB |
Output is correct |
31 |
Correct |
517 ms |
516 KB |
Output is correct |
32 |
Correct |
535 ms |
528 KB |
Output is correct |
33 |
Correct |
478 ms |
528 KB |
Output is correct |
34 |
Correct |
308 ms |
516 KB |
Output is correct |
35 |
Correct |
533 ms |
744 KB |
Output is correct |
36 |
Correct |
515 ms |
504 KB |
Output is correct |
37 |
Correct |
487 ms |
528 KB |
Output is correct |
38 |
Correct |
597 ms |
648 KB |
Output is correct |
39 |
Correct |
526 ms |
616 KB |
Output is correct |
40 |
Correct |
618 ms |
632 KB |
Output is correct |
41 |
Correct |
585 ms |
792 KB |
Output is correct |
42 |
Correct |
71 ms |
656 KB |
Output is correct |
43 |
Correct |
110 ms |
748 KB |
Output is correct |
44 |
Correct |
128 ms |
528 KB |
Output is correct |
45 |
Correct |
161 ms |
644 KB |
Output is correct |
46 |
Correct |
319 ms |
528 KB |
Output is correct |
47 |
Correct |
291 ms |
520 KB |
Output is correct |
48 |
Correct |
70 ms |
788 KB |
Output is correct |
49 |
Correct |
69 ms |
780 KB |
Output is correct |