#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
int x;
void dfs(int curr , int par , int hi , vector<vector<int>> &graph , int &cnt , vector<int> &ret){
if(hi%2 == 0){
ret[curr] = cnt;
cnt += 1;
}
for(auto i : graph[curr]){
if(i == par){
continue;
}
dfs(i,curr,hi+1,graph,cnt,ret);
}
if(hi%2 == 1){
ret[curr] = cnt;
cnt += 1;
}
}
vector<int> label(int n , int k , vector<int> u , vector<int> v){
vector<vector<int>> graph(1001);
int cnt = 0;
for(int i = 0 ; i < u.size() ; i += 1){
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
vector<int> labels(n);
dfs(0,0,0,graph,cnt,labels);
return labels;
}
int find_next_station(int s , int t , vector<int> c){
sort(c.begin(),c.end());
if(c.size() == 1){
return c[0];
}
if(s < c[0]){
if(t >= s && t <= c[c.size()-2]){
for(int i = 0 ; i < c.size() ; i += 1){
if(t <= c[i]){
return c[i];
}
}
}
return c.back();
}else{
if(t <= s && t >= c[1]){
for(int i = c.size()-1 ; i >= 0 ; i -= 1){
if(t >= c[i]){
return c[i];
}
}
}
return c[0];
}
}
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = 0 ; i < u.size() ; i += 1){
| ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:42:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0 ; i < c.size() ; i += 1){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
598 ms |
660 KB |
Output is correct |
2 |
Correct |
598 ms |
660 KB |
Output is correct |
3 |
Correct |
1057 ms |
472 KB |
Output is correct |
4 |
Correct |
647 ms |
528 KB |
Output is correct |
5 |
Correct |
675 ms |
528 KB |
Output is correct |
6 |
Correct |
514 ms |
520 KB |
Output is correct |
7 |
Correct |
458 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
608 KB |
Output is correct |
9 |
Correct |
4 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
579 ms |
492 KB |
Output is correct |
2 |
Correct |
481 ms |
576 KB |
Output is correct |
3 |
Correct |
883 ms |
528 KB |
Output is correct |
4 |
Correct |
890 ms |
400 KB |
Output is correct |
5 |
Correct |
646 ms |
528 KB |
Output is correct |
6 |
Correct |
636 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
609 ms |
620 KB |
Output is correct |
2 |
Correct |
523 ms |
528 KB |
Output is correct |
3 |
Correct |
883 ms |
504 KB |
Output is correct |
4 |
Correct |
664 ms |
508 KB |
Output is correct |
5 |
Correct |
772 ms |
528 KB |
Output is correct |
6 |
Correct |
452 ms |
656 KB |
Output is correct |
7 |
Correct |
501 ms |
616 KB |
Output is correct |
8 |
Correct |
3 ms |
600 KB |
Output is correct |
9 |
Correct |
4 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
718 ms |
488 KB |
Output is correct |
12 |
Correct |
596 ms |
696 KB |
Output is correct |
13 |
Correct |
501 ms |
692 KB |
Output is correct |
14 |
Correct |
571 ms |
528 KB |
Output is correct |
15 |
Correct |
72 ms |
600 KB |
Output is correct |
16 |
Correct |
72 ms |
588 KB |
Output is correct |
17 |
Correct |
141 ms |
580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1178 ms |
528 KB |
Output is correct |
2 |
Correct |
770 ms |
492 KB |
Output is correct |
3 |
Correct |
647 ms |
520 KB |
Output is correct |
4 |
Correct |
3 ms |
608 KB |
Output is correct |
5 |
Correct |
4 ms |
608 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
637 ms |
532 KB |
Output is correct |
8 |
Correct |
799 ms |
528 KB |
Output is correct |
9 |
Correct |
689 ms |
488 KB |
Output is correct |
10 |
Correct |
583 ms |
528 KB |
Output is correct |
11 |
Correct |
5 ms |
608 KB |
Output is correct |
12 |
Correct |
5 ms |
600 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
5 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
612 KB |
Output is correct |
16 |
Correct |
655 ms |
528 KB |
Output is correct |
17 |
Correct |
615 ms |
528 KB |
Output is correct |
18 |
Correct |
644 ms |
528 KB |
Output is correct |
19 |
Correct |
474 ms |
528 KB |
Output is correct |
20 |
Correct |
684 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
597 ms |
712 KB |
Output is correct |
2 |
Correct |
510 ms |
612 KB |
Output is correct |
3 |
Correct |
1047 ms |
492 KB |
Output is correct |
4 |
Correct |
850 ms |
556 KB |
Output is correct |
5 |
Correct |
672 ms |
532 KB |
Output is correct |
6 |
Correct |
477 ms |
656 KB |
Output is correct |
7 |
Correct |
529 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
608 KB |
Output is correct |
9 |
Correct |
5 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
474 ms |
532 KB |
Output is correct |
12 |
Correct |
584 ms |
488 KB |
Output is correct |
13 |
Correct |
1021 ms |
528 KB |
Output is correct |
14 |
Correct |
723 ms |
488 KB |
Output is correct |
15 |
Correct |
699 ms |
492 KB |
Output is correct |
16 |
Correct |
535 ms |
524 KB |
Output is correct |
17 |
Correct |
839 ms |
508 KB |
Output is correct |
18 |
Correct |
530 ms |
704 KB |
Output is correct |
19 |
Correct |
538 ms |
776 KB |
Output is correct |
20 |
Correct |
480 ms |
528 KB |
Output is correct |
21 |
Correct |
76 ms |
580 KB |
Output is correct |
22 |
Correct |
86 ms |
548 KB |
Output is correct |
23 |
Correct |
106 ms |
528 KB |
Output is correct |
24 |
Correct |
7 ms |
600 KB |
Output is correct |
25 |
Correct |
6 ms |
600 KB |
Output is correct |
26 |
Correct |
6 ms |
600 KB |
Output is correct |
27 |
Correct |
4 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
600 KB |
Output is correct |
29 |
Correct |
619 ms |
528 KB |
Output is correct |
30 |
Correct |
560 ms |
656 KB |
Output is correct |
31 |
Correct |
671 ms |
656 KB |
Output is correct |
32 |
Correct |
592 ms |
528 KB |
Output is correct |
33 |
Correct |
636 ms |
528 KB |
Output is correct |
34 |
Correct |
384 ms |
528 KB |
Output is correct |
35 |
Correct |
477 ms |
708 KB |
Output is correct |
36 |
Correct |
450 ms |
740 KB |
Output is correct |
37 |
Correct |
548 ms |
660 KB |
Output is correct |
38 |
Correct |
602 ms |
776 KB |
Output is correct |
39 |
Correct |
624 ms |
804 KB |
Output is correct |
40 |
Correct |
524 ms |
692 KB |
Output is correct |
41 |
Correct |
454 ms |
608 KB |
Output is correct |
42 |
Correct |
64 ms |
588 KB |
Output is correct |
43 |
Correct |
141 ms |
532 KB |
Output is correct |
44 |
Correct |
177 ms |
492 KB |
Output is correct |
45 |
Correct |
195 ms |
528 KB |
Output is correct |
46 |
Correct |
373 ms |
528 KB |
Output is correct |
47 |
Correct |
364 ms |
528 KB |
Output is correct |
48 |
Correct |
83 ms |
560 KB |
Output is correct |
49 |
Correct |
73 ms |
552 KB |
Output is correct |