#include "stations.h"
#include "bits/stdc++.h"
#define st first
#define nd second
using namespace std;
void dfs(int x, int p, vector<int>& h, vector<vector<int>>& g, vector<int>& path) {
h[x] = h[p] + 1;
path.push_back(x);
for(int i: g[x]) {
if(i != p) {
dfs(i, x, h, g, path);
}
}
path.push_back(x);
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n);
vector<vector<int>> g(n);
for(int i=0; i<n-1; ++i) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
for(int i=0; i<n; ++i) {
sort(g[i].begin(), g[i].end());
}
vector<int> h(n), path;
dfs(0, 0, h, g, path);
vector<vector<int>> pos(n);
for(int i=0; i<(int)path.size(); ++i) {
pos[path[i]].push_back(i);
}
vector<pair<int, int>> val(n);
for(int i=0; i<n; ++i) {
val[i].nd = i;
if(h[i]%2==1) {
val[i].st = pos[i][1];
}
else {
val[i].st = pos[i][0];
}
}
sort(val.begin(), val.end());
for(int i=0; i<n; ++i) {
labels[val[i].nd] = i;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
int sz = c.size();
sort(c.begin(), c.end());
if(c.size()==1) return c[0];
for(int i: c) if(t==i) return i;
if(c.back() > s) { // s is pre
int prv = s;
for(int i=0; i<sz-1; ++i) {
if(t > prv && t < c[i]) {
return c[i];
}
prv = c[i];
}
return c.back();
}
else { // s is post
int prv = s;
for(int i=sz-1; i>=1; --i) {
if(t < prv && t > c[i]) {
return c[i];
}
prv = c[i];
}
return c[0];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
574 ms |
1024 KB |
Output is correct |
2 |
Correct |
500 ms |
1008 KB |
Output is correct |
3 |
Correct |
898 ms |
644 KB |
Output is correct |
4 |
Correct |
664 ms |
644 KB |
Output is correct |
5 |
Correct |
651 ms |
640 KB |
Output is correct |
6 |
Correct |
511 ms |
1024 KB |
Output is correct |
7 |
Correct |
497 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
652 KB |
Output is correct |
9 |
Correct |
5 ms |
652 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
443 ms |
1024 KB |
Output is correct |
2 |
Correct |
570 ms |
1080 KB |
Output is correct |
3 |
Correct |
956 ms |
644 KB |
Output is correct |
4 |
Correct |
734 ms |
648 KB |
Output is correct |
5 |
Correct |
634 ms |
644 KB |
Output is correct |
6 |
Correct |
504 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
654 ms |
1008 KB |
Output is correct |
2 |
Correct |
497 ms |
1024 KB |
Output is correct |
3 |
Correct |
1016 ms |
640 KB |
Output is correct |
4 |
Correct |
740 ms |
640 KB |
Output is correct |
5 |
Correct |
737 ms |
640 KB |
Output is correct |
6 |
Correct |
455 ms |
1024 KB |
Output is correct |
7 |
Correct |
470 ms |
1024 KB |
Output is correct |
8 |
Correct |
4 ms |
656 KB |
Output is correct |
9 |
Correct |
4 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
648 KB |
Output is correct |
11 |
Correct |
617 ms |
644 KB |
Output is correct |
12 |
Correct |
529 ms |
1032 KB |
Output is correct |
13 |
Correct |
551 ms |
1024 KB |
Output is correct |
14 |
Correct |
464 ms |
1024 KB |
Output is correct |
15 |
Correct |
60 ms |
884 KB |
Output is correct |
16 |
Correct |
75 ms |
768 KB |
Output is correct |
17 |
Correct |
121 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
900 ms |
648 KB |
Output is correct |
2 |
Correct |
657 ms |
776 KB |
Output is correct |
3 |
Correct |
601 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
656 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
2 ms |
652 KB |
Output is correct |
7 |
Correct |
566 ms |
640 KB |
Output is correct |
8 |
Correct |
851 ms |
644 KB |
Output is correct |
9 |
Correct |
658 ms |
648 KB |
Output is correct |
10 |
Correct |
557 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
644 KB |
Output is correct |
12 |
Correct |
5 ms |
644 KB |
Output is correct |
13 |
Correct |
5 ms |
772 KB |
Output is correct |
14 |
Correct |
4 ms |
768 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
511 ms |
640 KB |
Output is correct |
17 |
Correct |
511 ms |
776 KB |
Output is correct |
18 |
Correct |
494 ms |
648 KB |
Output is correct |
19 |
Correct |
523 ms |
644 KB |
Output is correct |
20 |
Correct |
508 ms |
648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
532 ms |
1024 KB |
Output is correct |
2 |
Correct |
438 ms |
1024 KB |
Output is correct |
3 |
Correct |
915 ms |
652 KB |
Output is correct |
4 |
Correct |
674 ms |
776 KB |
Output is correct |
5 |
Correct |
630 ms |
784 KB |
Output is correct |
6 |
Correct |
439 ms |
1024 KB |
Output is correct |
7 |
Correct |
448 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
648 KB |
Output is correct |
9 |
Correct |
4 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
648 KB |
Output is correct |
11 |
Correct |
483 ms |
1008 KB |
Output is correct |
12 |
Correct |
584 ms |
1024 KB |
Output is correct |
13 |
Correct |
892 ms |
640 KB |
Output is correct |
14 |
Correct |
644 ms |
640 KB |
Output is correct |
15 |
Correct |
672 ms |
648 KB |
Output is correct |
16 |
Correct |
557 ms |
1024 KB |
Output is correct |
17 |
Correct |
616 ms |
640 KB |
Output is correct |
18 |
Correct |
504 ms |
1192 KB |
Output is correct |
19 |
Correct |
600 ms |
1168 KB |
Output is correct |
20 |
Correct |
600 ms |
1024 KB |
Output is correct |
21 |
Correct |
58 ms |
896 KB |
Output is correct |
22 |
Correct |
87 ms |
816 KB |
Output is correct |
23 |
Correct |
119 ms |
1024 KB |
Output is correct |
24 |
Correct |
7 ms |
644 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
5 ms |
644 KB |
Output is correct |
27 |
Correct |
4 ms |
640 KB |
Output is correct |
28 |
Correct |
2 ms |
640 KB |
Output is correct |
29 |
Correct |
603 ms |
648 KB |
Output is correct |
30 |
Correct |
509 ms |
748 KB |
Output is correct |
31 |
Correct |
516 ms |
648 KB |
Output is correct |
32 |
Correct |
580 ms |
640 KB |
Output is correct |
33 |
Correct |
614 ms |
644 KB |
Output is correct |
34 |
Correct |
349 ms |
1024 KB |
Output is correct |
35 |
Correct |
539 ms |
1024 KB |
Output is correct |
36 |
Correct |
581 ms |
1024 KB |
Output is correct |
37 |
Correct |
547 ms |
1024 KB |
Output is correct |
38 |
Correct |
557 ms |
1024 KB |
Output is correct |
39 |
Correct |
568 ms |
1024 KB |
Output is correct |
40 |
Correct |
475 ms |
1024 KB |
Output is correct |
41 |
Correct |
455 ms |
1096 KB |
Output is correct |
42 |
Correct |
67 ms |
768 KB |
Output is correct |
43 |
Correct |
114 ms |
904 KB |
Output is correct |
44 |
Correct |
146 ms |
1024 KB |
Output is correct |
45 |
Correct |
213 ms |
1024 KB |
Output is correct |
46 |
Correct |
404 ms |
768 KB |
Output is correct |
47 |
Correct |
321 ms |
1024 KB |
Output is correct |
48 |
Correct |
75 ms |
1280 KB |
Output is correct |
49 |
Correct |
80 ms |
1024 KB |
Output is correct |