#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N = 1e3 + 7;
vector<int> tin,tout,lv;
void dfs(vector<vector<int>> g, int x, int p, int &G)
{
tin[x] = G++;
for(auto y : g[x]){
if(y == p)continue;
lv[y] = 1 - lv[x];
dfs(g, y, x, G);
}
tout[x] = G++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
vector<vector<int>> g(n + 7);
tin.resize(n + 7);
tout.resize(n + 7);
lv.resize(n + 7);
for(int i = 0; i < n - 1; i++){
int x = u[i], y = v[i];
g[x].push_back(y);
g[y].push_back(x);
}
int st = 0;
dfs(g, 0, 0, st);
vector<int> op;
for(int i = 0; i < n; i++){
if(lv[i])labels[i] = tin[i];
else labels[i] = tout[i];
op.push_back(labels[i]);
}
sort(op.begin(), op.end());
st = 0;
vector<int> used(3 * n + 7, 0);
for(auto x : op){
used[x] = st++;
}
for(int i = 0; i < n; i++){
labels[i] = used[labels[i]];
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s < c[0]){
vector<pair<int, int>> nc;
int ls = s;
for(int i = 0; i + 1 < (int)c.size(); i++){
nc.push_back({ls, c[i]});
ls = c[i] + 1;
}
for(auto x : nc){
if(x.fi <= t && t <= x.se){
return x.se;
}
}
return c.back();
}else{
assert(s > c.back());
vector<pair<int, int>> nc;
int ls = s - 1;
for(int i = (int)c.size() - 1; i > 0; i--){
nc.push_back({c[i], ls});
ls = c[i] - 1;
}
for(auto x : nc){
if(x.fi <= t && t <= x.se){
return x.fi;
}
}
return c[0];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
961 ms |
55568 KB |
Output is correct |
2 |
Correct |
1475 ms |
55308 KB |
Output is correct |
3 |
Correct |
917 ms |
400 KB |
Output is correct |
4 |
Correct |
845 ms |
400 KB |
Output is correct |
5 |
Correct |
849 ms |
484 KB |
Output is correct |
6 |
Correct |
1279 ms |
49316 KB |
Output is correct |
7 |
Correct |
814 ms |
41776 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
524 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1237 ms |
1124 KB |
Output is correct |
2 |
Correct |
994 ms |
1128 KB |
Output is correct |
3 |
Correct |
1448 ms |
400 KB |
Output is correct |
4 |
Correct |
992 ms |
480 KB |
Output is correct |
5 |
Correct |
707 ms |
472 KB |
Output is correct |
6 |
Correct |
622 ms |
1096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1269 ms |
55692 KB |
Output is correct |
2 |
Correct |
1535 ms |
53236 KB |
Output is correct |
3 |
Correct |
1020 ms |
420 KB |
Output is correct |
4 |
Correct |
1172 ms |
472 KB |
Output is correct |
5 |
Correct |
723 ms |
564 KB |
Output is correct |
6 |
Correct |
1224 ms |
53624 KB |
Output is correct |
7 |
Correct |
876 ms |
42632 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
476 KB |
Output is correct |
10 |
Correct |
2 ms |
472 KB |
Output is correct |
11 |
Correct |
698 ms |
480 KB |
Output is correct |
12 |
Correct |
1441 ms |
54580 KB |
Output is correct |
13 |
Correct |
1583 ms |
50376 KB |
Output is correct |
14 |
Correct |
798 ms |
3136 KB |
Output is correct |
15 |
Correct |
59 ms |
400 KB |
Output is correct |
16 |
Correct |
260 ms |
700 KB |
Output is correct |
17 |
Correct |
745 ms |
832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1341 ms |
464 KB |
Output is correct |
2 |
Correct |
876 ms |
476 KB |
Output is correct |
3 |
Correct |
963 ms |
400 KB |
Output is correct |
4 |
Correct |
3 ms |
404 KB |
Output is correct |
5 |
Correct |
5 ms |
488 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
871 ms |
484 KB |
Output is correct |
8 |
Correct |
1418 ms |
460 KB |
Output is correct |
9 |
Correct |
828 ms |
488 KB |
Output is correct |
10 |
Correct |
1045 ms |
400 KB |
Output is correct |
11 |
Correct |
9 ms |
524 KB |
Output is correct |
12 |
Correct |
7 ms |
480 KB |
Output is correct |
13 |
Correct |
7 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
551 ms |
400 KB |
Output is correct |
17 |
Correct |
906 ms |
400 KB |
Output is correct |
18 |
Correct |
604 ms |
400 KB |
Output is correct |
19 |
Correct |
691 ms |
528 KB |
Output is correct |
20 |
Correct |
649 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1214 ms |
55672 KB |
Output is correct |
2 |
Correct |
1293 ms |
48944 KB |
Output is correct |
3 |
Correct |
1291 ms |
468 KB |
Output is correct |
4 |
Correct |
784 ms |
476 KB |
Output is correct |
5 |
Correct |
755 ms |
484 KB |
Output is correct |
6 |
Correct |
1346 ms |
55652 KB |
Output is correct |
7 |
Correct |
853 ms |
31192 KB |
Output is correct |
8 |
Correct |
3 ms |
476 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1130 ms |
1180 KB |
Output is correct |
12 |
Correct |
896 ms |
1072 KB |
Output is correct |
13 |
Correct |
1349 ms |
472 KB |
Output is correct |
14 |
Correct |
985 ms |
400 KB |
Output is correct |
15 |
Correct |
644 ms |
468 KB |
Output is correct |
16 |
Correct |
591 ms |
1040 KB |
Output is correct |
17 |
Correct |
749 ms |
612 KB |
Output is correct |
18 |
Correct |
1443 ms |
37492 KB |
Output is correct |
19 |
Correct |
1495 ms |
51768 KB |
Output is correct |
20 |
Correct |
799 ms |
4180 KB |
Output is correct |
21 |
Correct |
109 ms |
472 KB |
Output is correct |
22 |
Correct |
252 ms |
604 KB |
Output is correct |
23 |
Correct |
638 ms |
864 KB |
Output is correct |
24 |
Correct |
6 ms |
468 KB |
Output is correct |
25 |
Correct |
7 ms |
468 KB |
Output is correct |
26 |
Correct |
6 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
464 KB |
Output is correct |
29 |
Correct |
750 ms |
400 KB |
Output is correct |
30 |
Correct |
933 ms |
400 KB |
Output is correct |
31 |
Correct |
760 ms |
508 KB |
Output is correct |
32 |
Correct |
1016 ms |
400 KB |
Output is correct |
33 |
Correct |
683 ms |
488 KB |
Output is correct |
34 |
Correct |
956 ms |
42236 KB |
Output is correct |
35 |
Correct |
1697 ms |
55772 KB |
Output is correct |
36 |
Correct |
1353 ms |
46016 KB |
Output is correct |
37 |
Correct |
1452 ms |
13576 KB |
Output is correct |
38 |
Correct |
1371 ms |
13676 KB |
Output is correct |
39 |
Correct |
1409 ms |
17900 KB |
Output is correct |
40 |
Correct |
1404 ms |
17780 KB |
Output is correct |
41 |
Correct |
1304 ms |
14680 KB |
Output is correct |
42 |
Correct |
381 ms |
620 KB |
Output is correct |
43 |
Correct |
642 ms |
772 KB |
Output is correct |
44 |
Correct |
718 ms |
1168 KB |
Output is correct |
45 |
Correct |
865 ms |
1688 KB |
Output is correct |
46 |
Correct |
810 ms |
13896 KB |
Output is correct |
47 |
Correct |
1109 ms |
26872 KB |
Output is correct |
48 |
Correct |
697 ms |
1216 KB |
Output is correct |
49 |
Correct |
772 ms |
1100 KB |
Output is correct |