#include<bits/stdc++.h>
#include "stations.h"
using namespace std;
#define vi vector<int>
#define pb push_back
#define REP(i,n) for(int i = 0; i < n; i ++)
#define FOR(i,a,b) for(int i = a; i < b; i ++)
const int MAXN = 1005;
int st[MAXN],fin[MAXN],dep[MAXN],tim = 0;
vi adj[MAXN];
void dfs(int u,int p,int d){
if(d%2 == 0) st[u] = tim++;
dep[u] = d;
for(auto v:adj[u]){
if(v != p) dfs(v,u,d+1);
}
if(d%2 == 1) fin[u] = tim++;
}
vi label(int n, int k, vi u, vi v){
tim = 0;
REP(i,n) adj[i].clear();
vi labels(n);
REP(i,n-1){
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
dfs(0,0,0);
for (int i = 0; i < n; i++){
if(dep[i]%2 == 0) labels[i] = st[i];
else labels[i] = fin[i];
}
return labels;
}
int find_next_station(int s, int t, vi c){
if(c.size() == 1) return c[0];
for(auto x:c){
if(x == t) return x;
}
sort(c.begin(),c.end());
if(s < c[0]){
if(t < s) return c.back();
for(auto x:c){
if(t < x) return x;
}
return c.back();
}
else{
reverse(c.begin(),c.end());
if(t > s) return c.back();
for(auto x:c){
if(t > x) return x;
}
return c.back();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
701 ms |
1068 KB |
Output is correct |
2 |
Correct |
609 ms |
1064 KB |
Output is correct |
3 |
Correct |
1132 ms |
940 KB |
Output is correct |
4 |
Correct |
920 ms |
940 KB |
Output is correct |
5 |
Correct |
824 ms |
940 KB |
Output is correct |
6 |
Correct |
518 ms |
992 KB |
Output is correct |
7 |
Correct |
589 ms |
992 KB |
Output is correct |
8 |
Correct |
3 ms |
988 KB |
Output is correct |
9 |
Correct |
5 ms |
948 KB |
Output is correct |
10 |
Correct |
2 ms |
992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
566 ms |
876 KB |
Output is correct |
2 |
Correct |
629 ms |
1136 KB |
Output is correct |
3 |
Correct |
983 ms |
1012 KB |
Output is correct |
4 |
Correct |
784 ms |
1120 KB |
Output is correct |
5 |
Correct |
702 ms |
940 KB |
Output is correct |
6 |
Correct |
517 ms |
712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
663 ms |
948 KB |
Output is correct |
2 |
Correct |
534 ms |
1064 KB |
Output is correct |
3 |
Correct |
948 ms |
992 KB |
Output is correct |
4 |
Correct |
669 ms |
940 KB |
Output is correct |
5 |
Correct |
573 ms |
864 KB |
Output is correct |
6 |
Correct |
421 ms |
1068 KB |
Output is correct |
7 |
Correct |
442 ms |
1220 KB |
Output is correct |
8 |
Correct |
3 ms |
940 KB |
Output is correct |
9 |
Correct |
5 ms |
736 KB |
Output is correct |
10 |
Correct |
2 ms |
736 KB |
Output is correct |
11 |
Correct |
562 ms |
736 KB |
Output is correct |
12 |
Correct |
454 ms |
1192 KB |
Output is correct |
13 |
Correct |
524 ms |
992 KB |
Output is correct |
14 |
Correct |
518 ms |
736 KB |
Output is correct |
15 |
Correct |
58 ms |
940 KB |
Output is correct |
16 |
Correct |
65 ms |
908 KB |
Output is correct |
17 |
Correct |
101 ms |
1012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
889 ms |
992 KB |
Output is correct |
2 |
Correct |
732 ms |
1108 KB |
Output is correct |
3 |
Correct |
570 ms |
864 KB |
Output is correct |
4 |
Correct |
3 ms |
940 KB |
Output is correct |
5 |
Correct |
5 ms |
736 KB |
Output is correct |
6 |
Correct |
3 ms |
940 KB |
Output is correct |
7 |
Correct |
744 ms |
864 KB |
Output is correct |
8 |
Correct |
1077 ms |
736 KB |
Output is correct |
9 |
Correct |
741 ms |
948 KB |
Output is correct |
10 |
Correct |
620 ms |
940 KB |
Output is correct |
11 |
Correct |
8 ms |
736 KB |
Output is correct |
12 |
Correct |
7 ms |
736 KB |
Output is correct |
13 |
Correct |
6 ms |
736 KB |
Output is correct |
14 |
Correct |
5 ms |
940 KB |
Output is correct |
15 |
Correct |
3 ms |
736 KB |
Output is correct |
16 |
Correct |
586 ms |
896 KB |
Output is correct |
17 |
Correct |
540 ms |
864 KB |
Output is correct |
18 |
Correct |
485 ms |
992 KB |
Output is correct |
19 |
Correct |
516 ms |
864 KB |
Output is correct |
20 |
Correct |
616 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
670 ms |
904 KB |
Output is correct |
2 |
Correct |
492 ms |
992 KB |
Output is correct |
3 |
Correct |
965 ms |
1108 KB |
Output is correct |
4 |
Correct |
836 ms |
940 KB |
Output is correct |
5 |
Correct |
708 ms |
956 KB |
Output is correct |
6 |
Correct |
622 ms |
992 KB |
Output is correct |
7 |
Correct |
588 ms |
864 KB |
Output is correct |
8 |
Correct |
4 ms |
736 KB |
Output is correct |
9 |
Correct |
6 ms |
864 KB |
Output is correct |
10 |
Correct |
2 ms |
864 KB |
Output is correct |
11 |
Correct |
568 ms |
884 KB |
Output is correct |
12 |
Correct |
702 ms |
892 KB |
Output is correct |
13 |
Correct |
990 ms |
940 KB |
Output is correct |
14 |
Correct |
698 ms |
736 KB |
Output is correct |
15 |
Correct |
624 ms |
1068 KB |
Output is correct |
16 |
Correct |
567 ms |
892 KB |
Output is correct |
17 |
Correct |
579 ms |
736 KB |
Output is correct |
18 |
Correct |
593 ms |
1220 KB |
Output is correct |
19 |
Correct |
517 ms |
992 KB |
Output is correct |
20 |
Correct |
454 ms |
900 KB |
Output is correct |
21 |
Correct |
68 ms |
736 KB |
Output is correct |
22 |
Correct |
72 ms |
736 KB |
Output is correct |
23 |
Correct |
102 ms |
884 KB |
Output is correct |
24 |
Correct |
7 ms |
948 KB |
Output is correct |
25 |
Correct |
6 ms |
940 KB |
Output is correct |
26 |
Correct |
6 ms |
736 KB |
Output is correct |
27 |
Correct |
5 ms |
864 KB |
Output is correct |
28 |
Correct |
2 ms |
864 KB |
Output is correct |
29 |
Correct |
604 ms |
736 KB |
Output is correct |
30 |
Correct |
581 ms |
940 KB |
Output is correct |
31 |
Correct |
625 ms |
864 KB |
Output is correct |
32 |
Correct |
697 ms |
940 KB |
Output is correct |
33 |
Correct |
459 ms |
940 KB |
Output is correct |
34 |
Correct |
374 ms |
1080 KB |
Output is correct |
35 |
Correct |
453 ms |
1056 KB |
Output is correct |
36 |
Correct |
438 ms |
1076 KB |
Output is correct |
37 |
Correct |
529 ms |
1224 KB |
Output is correct |
38 |
Correct |
511 ms |
896 KB |
Output is correct |
39 |
Correct |
565 ms |
1376 KB |
Output is correct |
40 |
Correct |
456 ms |
944 KB |
Output is correct |
41 |
Correct |
589 ms |
1248 KB |
Output is correct |
42 |
Correct |
82 ms |
888 KB |
Output is correct |
43 |
Correct |
114 ms |
864 KB |
Output is correct |
44 |
Correct |
118 ms |
1252 KB |
Output is correct |
45 |
Correct |
153 ms |
864 KB |
Output is correct |
46 |
Correct |
299 ms |
1020 KB |
Output is correct |
47 |
Correct |
276 ms |
1108 KB |
Output is correct |
48 |
Correct |
57 ms |
1136 KB |
Output is correct |
49 |
Correct |
67 ms |
1080 KB |
Output is correct |