#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> label(int n, int k, std::vector<int> U, std::vector<int> V) {
std::vector<int> labels(n);
vector<vector<int>> edge(n);
for(int i=0;i<n-1;i++){
edge[U[i]].push_back(V[i]);
edge[V[i]].push_back(U[i]);
}
int num=0;
function<void(int,int,int)> dfs;
dfs = [&](int u,int p,int d){
if(d==0) labels[u]=num++;
for(int v:edge[u]){
if(v==p) continue;
dfs(v,u,d^1);
}
if(d==1) labels[u]=num++;
};
dfs(0,-1,0);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c){
sort(c.begin(),c.end());
if(c.back()<s){
c.push_back(s);
for(int i=1;i<(int)c.size()-1;i++){
if(t>=c[i] && t<c[i+1]) return c[i];
}
return c.front();
}
else{
if(t>s && t<=c[0]) return c[0];
for(int i=1;i<(int)c.size();i++){
if(t>c[i-1] && t<=c[i]) return c[i];
}
return c.back();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
561 ms |
628 KB |
Output is correct |
2 |
Correct |
369 ms |
636 KB |
Output is correct |
3 |
Correct |
810 ms |
512 KB |
Output is correct |
4 |
Correct |
581 ms |
416 KB |
Output is correct |
5 |
Correct |
586 ms |
512 KB |
Output is correct |
6 |
Correct |
437 ms |
548 KB |
Output is correct |
7 |
Correct |
484 ms |
536 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
423 ms |
480 KB |
Output is correct |
2 |
Correct |
486 ms |
548 KB |
Output is correct |
3 |
Correct |
927 ms |
420 KB |
Output is correct |
4 |
Correct |
693 ms |
504 KB |
Output is correct |
5 |
Correct |
587 ms |
420 KB |
Output is correct |
6 |
Correct |
473 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
627 ms |
668 KB |
Output is correct |
2 |
Correct |
413 ms |
676 KB |
Output is correct |
3 |
Correct |
912 ms |
420 KB |
Output is correct |
4 |
Correct |
716 ms |
508 KB |
Output is correct |
5 |
Correct |
596 ms |
504 KB |
Output is correct |
6 |
Correct |
374 ms |
628 KB |
Output is correct |
7 |
Correct |
467 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
496 KB |
Output is correct |
9 |
Correct |
3 ms |
500 KB |
Output is correct |
10 |
Correct |
2 ms |
500 KB |
Output is correct |
11 |
Correct |
526 ms |
504 KB |
Output is correct |
12 |
Correct |
497 ms |
756 KB |
Output is correct |
13 |
Correct |
465 ms |
712 KB |
Output is correct |
14 |
Correct |
428 ms |
504 KB |
Output is correct |
15 |
Correct |
53 ms |
444 KB |
Output is correct |
16 |
Correct |
54 ms |
548 KB |
Output is correct |
17 |
Correct |
102 ms |
548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
845 ms |
504 KB |
Output is correct |
2 |
Correct |
672 ms |
512 KB |
Output is correct |
3 |
Correct |
447 ms |
500 KB |
Output is correct |
4 |
Correct |
3 ms |
488 KB |
Output is correct |
5 |
Correct |
4 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
500 KB |
Output is correct |
7 |
Correct |
576 ms |
420 KB |
Output is correct |
8 |
Correct |
806 ms |
488 KB |
Output is correct |
9 |
Correct |
701 ms |
416 KB |
Output is correct |
10 |
Correct |
586 ms |
496 KB |
Output is correct |
11 |
Correct |
3 ms |
492 KB |
Output is correct |
12 |
Correct |
5 ms |
500 KB |
Output is correct |
13 |
Correct |
3 ms |
568 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
462 ms |
512 KB |
Output is correct |
17 |
Correct |
402 ms |
512 KB |
Output is correct |
18 |
Correct |
540 ms |
420 KB |
Output is correct |
19 |
Correct |
573 ms |
420 KB |
Output is correct |
20 |
Correct |
409 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
578 ms |
616 KB |
Output is correct |
2 |
Correct |
480 ms |
628 KB |
Output is correct |
3 |
Correct |
661 ms |
416 KB |
Output is correct |
4 |
Correct |
678 ms |
548 KB |
Output is correct |
5 |
Correct |
667 ms |
508 KB |
Output is correct |
6 |
Correct |
513 ms |
636 KB |
Output is correct |
7 |
Correct |
502 ms |
540 KB |
Output is correct |
8 |
Correct |
1 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
490 ms |
496 KB |
Output is correct |
12 |
Correct |
480 ms |
552 KB |
Output is correct |
13 |
Correct |
900 ms |
480 KB |
Output is correct |
14 |
Correct |
618 ms |
508 KB |
Output is correct |
15 |
Correct |
599 ms |
416 KB |
Output is correct |
16 |
Correct |
467 ms |
540 KB |
Output is correct |
17 |
Correct |
672 ms |
416 KB |
Output is correct |
18 |
Correct |
504 ms |
624 KB |
Output is correct |
19 |
Correct |
502 ms |
716 KB |
Output is correct |
20 |
Correct |
449 ms |
484 KB |
Output is correct |
21 |
Correct |
53 ms |
488 KB |
Output is correct |
22 |
Correct |
65 ms |
532 KB |
Output is correct |
23 |
Correct |
105 ms |
668 KB |
Output is correct |
24 |
Correct |
6 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
500 KB |
Output is correct |
27 |
Correct |
2 ms |
504 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
551 ms |
528 KB |
Output is correct |
30 |
Correct |
563 ms |
420 KB |
Output is correct |
31 |
Correct |
404 ms |
420 KB |
Output is correct |
32 |
Correct |
467 ms |
420 KB |
Output is correct |
33 |
Correct |
464 ms |
508 KB |
Output is correct |
34 |
Correct |
370 ms |
676 KB |
Output is correct |
35 |
Correct |
387 ms |
804 KB |
Output is correct |
36 |
Correct |
413 ms |
632 KB |
Output is correct |
37 |
Correct |
475 ms |
708 KB |
Output is correct |
38 |
Correct |
455 ms |
716 KB |
Output is correct |
39 |
Correct |
406 ms |
804 KB |
Output is correct |
40 |
Correct |
429 ms |
620 KB |
Output is correct |
41 |
Correct |
482 ms |
664 KB |
Output is correct |
42 |
Correct |
60 ms |
496 KB |
Output is correct |
43 |
Correct |
73 ms |
572 KB |
Output is correct |
44 |
Correct |
110 ms |
572 KB |
Output is correct |
45 |
Correct |
141 ms |
508 KB |
Output is correct |
46 |
Correct |
311 ms |
548 KB |
Output is correct |
47 |
Correct |
323 ms |
632 KB |
Output is correct |
48 |
Correct |
57 ms |
612 KB |
Output is correct |
49 |
Correct |
55 ms |
676 KB |
Output is correct |