#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
vector<pair<int,int>> lab;
int in[1000],out[1000];
vector<int> ed[1000];
int cur;
void dfs(int x,int dep){
in[x]=cur;cur++;
for(int i=0;i<ed[x].size();i++){
int y=ed[x][i];
if(in[y]!=-1)continue;
dfs(y,dep+1);
}
out[x]=cur;cur++;
if(dep%2==0)lab.PB(MP(in[x],x));
else lab.PB(MP(out[x],x));
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
memset(in,-1,sizeof(in));
memset(out,-1,sizeof(out));
lab.clear();
for(int i=0;i<n;i++)ed[i].clear();
for(int i=0;i<n-1;i++){
ed[u[i]].PB(v[i]);
ed[v[i]].PB(u[i]);
}
cur=0;
dfs(0,0);
sort(lab.begin(),lab.end());
vector<int> labels(n);
for(int i=0;i<n;i++){
labels[lab[i].S]=i;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(),c.end());
if(s<c[0]){
int par=c.back();
if(s!=0)c.pop_back();
if(t<s)return par;
for(int i=0;i<c.size();i++){
if(t<=c[i])return c[i];
}
return par;
}
else{
if(t>s)return c[0];
for(int i=c.size()-1;i>0;i--){
if(t>=c[i])return c[i];
}
return c[0];
}
return c[0];
}
Compilation message
stations.cpp: In function 'void dfs(int, int)':
stations.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i=0;i<ed[x].size();i++){
| ~^~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:48:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i=0;i<c.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
540 ms |
664 KB |
Output is correct |
2 |
Correct |
436 ms |
656 KB |
Output is correct |
3 |
Correct |
1031 ms |
548 KB |
Output is correct |
4 |
Correct |
647 ms |
532 KB |
Output is correct |
5 |
Correct |
523 ms |
532 KB |
Output is correct |
6 |
Correct |
546 ms |
788 KB |
Output is correct |
7 |
Correct |
449 ms |
644 KB |
Output is correct |
8 |
Correct |
2 ms |
500 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
442 ms |
536 KB |
Output is correct |
2 |
Correct |
534 ms |
536 KB |
Output is correct |
3 |
Correct |
849 ms |
540 KB |
Output is correct |
4 |
Correct |
608 ms |
416 KB |
Output is correct |
5 |
Correct |
582 ms |
536 KB |
Output is correct |
6 |
Correct |
436 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
495 ms |
672 KB |
Output is correct |
2 |
Correct |
436 ms |
648 KB |
Output is correct |
3 |
Correct |
847 ms |
416 KB |
Output is correct |
4 |
Correct |
614 ms |
524 KB |
Output is correct |
5 |
Correct |
526 ms |
532 KB |
Output is correct |
6 |
Correct |
468 ms |
652 KB |
Output is correct |
7 |
Correct |
455 ms |
520 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
11 |
Correct |
625 ms |
536 KB |
Output is correct |
12 |
Correct |
403 ms |
796 KB |
Output is correct |
13 |
Correct |
376 ms |
800 KB |
Output is correct |
14 |
Correct |
465 ms |
612 KB |
Output is correct |
15 |
Correct |
41 ms |
612 KB |
Output is correct |
16 |
Correct |
56 ms |
620 KB |
Output is correct |
17 |
Correct |
103 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
857 ms |
532 KB |
Output is correct |
2 |
Correct |
687 ms |
420 KB |
Output is correct |
3 |
Correct |
473 ms |
420 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
628 KB |
Output is correct |
6 |
Correct |
0 ms |
504 KB |
Output is correct |
7 |
Correct |
591 ms |
544 KB |
Output is correct |
8 |
Correct |
792 ms |
420 KB |
Output is correct |
9 |
Correct |
694 ms |
548 KB |
Output is correct |
10 |
Correct |
604 ms |
748 KB |
Output is correct |
11 |
Correct |
6 ms |
492 KB |
Output is correct |
12 |
Correct |
3 ms |
496 KB |
Output is correct |
13 |
Correct |
4 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
406 ms |
416 KB |
Output is correct |
17 |
Correct |
514 ms |
536 KB |
Output is correct |
18 |
Correct |
425 ms |
416 KB |
Output is correct |
19 |
Correct |
513 ms |
532 KB |
Output is correct |
20 |
Correct |
524 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
567 ms |
664 KB |
Output is correct |
2 |
Correct |
495 ms |
640 KB |
Output is correct |
3 |
Correct |
910 ms |
420 KB |
Output is correct |
4 |
Correct |
606 ms |
524 KB |
Output is correct |
5 |
Correct |
604 ms |
536 KB |
Output is correct |
6 |
Correct |
412 ms |
756 KB |
Output is correct |
7 |
Correct |
393 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
372 ms |
536 KB |
Output is correct |
12 |
Correct |
397 ms |
548 KB |
Output is correct |
13 |
Correct |
863 ms |
484 KB |
Output is correct |
14 |
Correct |
552 ms |
416 KB |
Output is correct |
15 |
Correct |
549 ms |
420 KB |
Output is correct |
16 |
Correct |
411 ms |
524 KB |
Output is correct |
17 |
Correct |
541 ms |
420 KB |
Output is correct |
18 |
Correct |
521 ms |
756 KB |
Output is correct |
19 |
Correct |
535 ms |
932 KB |
Output is correct |
20 |
Correct |
419 ms |
524 KB |
Output is correct |
21 |
Correct |
52 ms |
624 KB |
Output is correct |
22 |
Correct |
54 ms |
664 KB |
Output is correct |
23 |
Correct |
89 ms |
696 KB |
Output is correct |
24 |
Correct |
6 ms |
496 KB |
Output is correct |
25 |
Correct |
6 ms |
500 KB |
Output is correct |
26 |
Correct |
4 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
555 ms |
564 KB |
Output is correct |
30 |
Correct |
481 ms |
416 KB |
Output is correct |
31 |
Correct |
500 ms |
528 KB |
Output is correct |
32 |
Correct |
607 ms |
536 KB |
Output is correct |
33 |
Correct |
597 ms |
416 KB |
Output is correct |
34 |
Correct |
372 ms |
660 KB |
Output is correct |
35 |
Correct |
454 ms |
788 KB |
Output is correct |
36 |
Correct |
349 ms |
804 KB |
Output is correct |
37 |
Correct |
410 ms |
628 KB |
Output is correct |
38 |
Correct |
411 ms |
644 KB |
Output is correct |
39 |
Correct |
463 ms |
772 KB |
Output is correct |
40 |
Correct |
444 ms |
656 KB |
Output is correct |
41 |
Correct |
510 ms |
720 KB |
Output is correct |
42 |
Correct |
54 ms |
544 KB |
Output is correct |
43 |
Correct |
129 ms |
656 KB |
Output is correct |
44 |
Correct |
142 ms |
632 KB |
Output is correct |
45 |
Correct |
113 ms |
612 KB |
Output is correct |
46 |
Correct |
267 ms |
524 KB |
Output is correct |
47 |
Correct |
357 ms |
660 KB |
Output is correct |
48 |
Correct |
52 ms |
664 KB |
Output is correct |
49 |
Correct |
52 ms |
752 KB |
Output is correct |