#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 3;
vector<int> adj[N];
int dfs(int u, int p, int idx, bool big, vector<int> &labels){
if(!big) labels[u] = idx++;
for(int to: adj[u]){
if(to == p) continue;
idx = dfs(to, u, idx, !big, labels);
}
if(big) labels[u] = idx++;
return idx;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
for(int i = 0; i < n; ++i)
adj[i].clear();
for(int i = 0; i < n - 1; ++i){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
vector<int> labels(n);
dfs(0, -1, 0, true, labels);
return labels;
}
int find_next_station(int s, int t, vector<int> c){
if(c.size() == 1) return c[0];
if(s < c[0]){
if(t < s) return c.back();
for(int i = 0; i < (int)c.size() - 1; ++i)
if(t <= c[i])
return c[i];
return c.back();
}
if(t > s || t < c[1]) return c[0];
for(int i = 2; i < (int)c.size(); ++i)
if(t < c[i])
return c[i - 1];
return c[(int)c.size() - 1];
}
/*
2
5 10
0 1
0 2
1 3
1 4
1
0 4 0
2 1
0 1
1
1 0 0
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
545 ms |
1024 KB |
Output is correct |
2 |
Correct |
514 ms |
1024 KB |
Output is correct |
3 |
Correct |
1160 ms |
880 KB |
Output is correct |
4 |
Correct |
780 ms |
872 KB |
Output is correct |
5 |
Correct |
622 ms |
872 KB |
Output is correct |
6 |
Correct |
457 ms |
1024 KB |
Output is correct |
7 |
Correct |
436 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
884 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
467 ms |
768 KB |
Output is correct |
2 |
Correct |
638 ms |
832 KB |
Output is correct |
3 |
Correct |
878 ms |
884 KB |
Output is correct |
4 |
Correct |
666 ms |
768 KB |
Output is correct |
5 |
Correct |
566 ms |
888 KB |
Output is correct |
6 |
Correct |
489 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
591 ms |
1024 KB |
Output is correct |
2 |
Correct |
467 ms |
1024 KB |
Output is correct |
3 |
Correct |
1041 ms |
768 KB |
Output is correct |
4 |
Correct |
762 ms |
768 KB |
Output is correct |
5 |
Correct |
734 ms |
888 KB |
Output is correct |
6 |
Correct |
516 ms |
1024 KB |
Output is correct |
7 |
Correct |
466 ms |
776 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
1 ms |
892 KB |
Output is correct |
11 |
Correct |
594 ms |
768 KB |
Output is correct |
12 |
Correct |
458 ms |
1116 KB |
Output is correct |
13 |
Correct |
531 ms |
1024 KB |
Output is correct |
14 |
Correct |
457 ms |
832 KB |
Output is correct |
15 |
Correct |
64 ms |
768 KB |
Output is correct |
16 |
Correct |
86 ms |
848 KB |
Output is correct |
17 |
Correct |
111 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
869 ms |
768 KB |
Output is correct |
2 |
Correct |
672 ms |
1008 KB |
Output is correct |
3 |
Correct |
582 ms |
872 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
872 KB |
Output is correct |
6 |
Correct |
2 ms |
884 KB |
Output is correct |
7 |
Correct |
585 ms |
876 KB |
Output is correct |
8 |
Correct |
913 ms |
1032 KB |
Output is correct |
9 |
Correct |
657 ms |
896 KB |
Output is correct |
10 |
Correct |
581 ms |
880 KB |
Output is correct |
11 |
Correct |
7 ms |
888 KB |
Output is correct |
12 |
Correct |
7 ms |
768 KB |
Output is correct |
13 |
Correct |
6 ms |
768 KB |
Output is correct |
14 |
Correct |
3 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
876 KB |
Output is correct |
16 |
Correct |
650 ms |
768 KB |
Output is correct |
17 |
Correct |
579 ms |
880 KB |
Output is correct |
18 |
Correct |
537 ms |
880 KB |
Output is correct |
19 |
Correct |
544 ms |
872 KB |
Output is correct |
20 |
Correct |
576 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
548 ms |
1024 KB |
Output is correct |
2 |
Correct |
478 ms |
1024 KB |
Output is correct |
3 |
Correct |
881 ms |
1044 KB |
Output is correct |
4 |
Correct |
659 ms |
876 KB |
Output is correct |
5 |
Correct |
600 ms |
768 KB |
Output is correct |
6 |
Correct |
442 ms |
1024 KB |
Output is correct |
7 |
Correct |
576 ms |
1052 KB |
Output is correct |
8 |
Correct |
3 ms |
880 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
876 KB |
Output is correct |
11 |
Correct |
441 ms |
816 KB |
Output is correct |
12 |
Correct |
524 ms |
824 KB |
Output is correct |
13 |
Correct |
880 ms |
1032 KB |
Output is correct |
14 |
Correct |
649 ms |
768 KB |
Output is correct |
15 |
Correct |
600 ms |
768 KB |
Output is correct |
16 |
Correct |
463 ms |
768 KB |
Output is correct |
17 |
Correct |
595 ms |
768 KB |
Output is correct |
18 |
Correct |
481 ms |
884 KB |
Output is correct |
19 |
Correct |
469 ms |
1116 KB |
Output is correct |
20 |
Correct |
462 ms |
828 KB |
Output is correct |
21 |
Correct |
50 ms |
872 KB |
Output is correct |
22 |
Correct |
96 ms |
848 KB |
Output is correct |
23 |
Correct |
125 ms |
812 KB |
Output is correct |
24 |
Correct |
9 ms |
872 KB |
Output is correct |
25 |
Correct |
8 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
768 KB |
Output is correct |
27 |
Correct |
5 ms |
880 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
29 |
Correct |
660 ms |
768 KB |
Output is correct |
30 |
Correct |
721 ms |
768 KB |
Output is correct |
31 |
Correct |
766 ms |
776 KB |
Output is correct |
32 |
Correct |
492 ms |
872 KB |
Output is correct |
33 |
Correct |
613 ms |
888 KB |
Output is correct |
34 |
Correct |
342 ms |
768 KB |
Output is correct |
35 |
Correct |
490 ms |
1008 KB |
Output is correct |
36 |
Correct |
490 ms |
1024 KB |
Output is correct |
37 |
Correct |
534 ms |
768 KB |
Output is correct |
38 |
Correct |
628 ms |
1048 KB |
Output is correct |
39 |
Correct |
466 ms |
768 KB |
Output is correct |
40 |
Correct |
565 ms |
772 KB |
Output is correct |
41 |
Correct |
540 ms |
916 KB |
Output is correct |
42 |
Correct |
78 ms |
828 KB |
Output is correct |
43 |
Correct |
141 ms |
768 KB |
Output is correct |
44 |
Correct |
175 ms |
800 KB |
Output is correct |
45 |
Correct |
224 ms |
768 KB |
Output is correct |
46 |
Correct |
313 ms |
1152 KB |
Output is correct |
47 |
Correct |
314 ms |
768 KB |
Output is correct |
48 |
Correct |
65 ms |
776 KB |
Output is correct |
49 |
Correct |
65 ms |
1028 KB |
Output is correct |