#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> trio;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
int t;
vector<tuple<int,int,int>> val;
vector<int> labels;
vector<vector<int>> edges;
void dfs(int x, int pai, int niv) {
t++;
if(niv%2 == 0) labels[x] = t;
for(int viz : edges[x]) if(viz != pai) dfs(viz, x, niv+1);
if(niv%2 == 1) labels[x] = t;
val.pb({labels[x], niv, x});
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
labels.clear();
edges.clear();
val.clear();
labels.resize(n);
edges.resize(n);
t = -1;
for(int i = 0; i < n-1; i++) edges[u[i]].pb(v[i]), edges[v[i]].pb(u[i]);
dfs(0, -1, 0);
sort(all(val), [](trio a, trio b){
if(get<0>(a) != get<0>(b)) return get<0>(a) < get<0>(b);
return get<1>(a) > get<1>(b);
});
for(int i = 0; i < n; i++) {
int ind = get<2>(val[i]);
labels[ind] = i;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
// primeiro descobrir se S guarda t_in ou t_out
// se S guarda t_out, então t_in[viz] < t_out[s]
// caso contrario, t_out[viz] > t_in[s]
if(sz(c) == 1) return c[0];
if(c.back() < s) {
// S guarda t_out
int t_in = c[1] - 1, t_out = s;
if(t < t_in or t_out < t) return c[0];
// caso contrário t está na sub de s
// sub[viz] = {t_in[viz], t_in[viz+1]-1}
// basta achar o primeiro cara tal que x < c[viz], a resposta é o cara anterior
auto ptr = upper_bound(all(c), t);
ptr--;
return *ptr;
}
else {
// S guarda t_in
int t_in = s, t_out = c[sz(c) - 2];
if(t < t_in or t_out < t) return c.back();
// caso contrário t está na sub de s
// sub[viz] = {t_out[viz-1]+1, t_out[viz]}
auto ptr = lower_bound(all(c), t);
return *ptr;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
308 ms |
940 KB |
Output is correct |
2 |
Correct |
264 ms |
940 KB |
Output is correct |
3 |
Correct |
543 ms |
684 KB |
Output is correct |
4 |
Correct |
370 ms |
684 KB |
Output is correct |
5 |
Correct |
317 ms |
684 KB |
Output is correct |
6 |
Correct |
276 ms |
940 KB |
Output is correct |
7 |
Correct |
273 ms |
940 KB |
Output is correct |
8 |
Correct |
0 ms |
776 KB |
Output is correct |
9 |
Correct |
2 ms |
764 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
772 KB |
Output is correct |
2 |
Correct |
271 ms |
712 KB |
Output is correct |
3 |
Correct |
492 ms |
688 KB |
Output is correct |
4 |
Correct |
400 ms |
684 KB |
Output is correct |
5 |
Correct |
347 ms |
684 KB |
Output is correct |
6 |
Correct |
238 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
288 ms |
968 KB |
Output is correct |
2 |
Correct |
248 ms |
1452 KB |
Output is correct |
3 |
Correct |
529 ms |
936 KB |
Output is correct |
4 |
Correct |
371 ms |
936 KB |
Output is correct |
5 |
Correct |
338 ms |
684 KB |
Output is correct |
6 |
Correct |
288 ms |
944 KB |
Output is correct |
7 |
Correct |
223 ms |
940 KB |
Output is correct |
8 |
Correct |
0 ms |
776 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
11 |
Correct |
309 ms |
684 KB |
Output is correct |
12 |
Correct |
236 ms |
1016 KB |
Output is correct |
13 |
Correct |
251 ms |
1024 KB |
Output is correct |
14 |
Correct |
234 ms |
684 KB |
Output is correct |
15 |
Correct |
22 ms |
776 KB |
Output is correct |
16 |
Correct |
28 ms |
776 KB |
Output is correct |
17 |
Correct |
50 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
516 ms |
684 KB |
Output is correct |
2 |
Correct |
365 ms |
684 KB |
Output is correct |
3 |
Correct |
331 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
776 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
0 ms |
776 KB |
Output is correct |
7 |
Correct |
323 ms |
684 KB |
Output is correct |
8 |
Correct |
507 ms |
684 KB |
Output is correct |
9 |
Correct |
356 ms |
684 KB |
Output is correct |
10 |
Correct |
332 ms |
684 KB |
Output is correct |
11 |
Correct |
1 ms |
776 KB |
Output is correct |
12 |
Correct |
2 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
764 KB |
Output is correct |
14 |
Correct |
1 ms |
776 KB |
Output is correct |
15 |
Correct |
0 ms |
776 KB |
Output is correct |
16 |
Correct |
277 ms |
772 KB |
Output is correct |
17 |
Correct |
290 ms |
684 KB |
Output is correct |
18 |
Correct |
287 ms |
684 KB |
Output is correct |
19 |
Correct |
277 ms |
684 KB |
Output is correct |
20 |
Correct |
297 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
291 ms |
940 KB |
Output is correct |
2 |
Correct |
257 ms |
940 KB |
Output is correct |
3 |
Correct |
529 ms |
684 KB |
Output is correct |
4 |
Correct |
387 ms |
684 KB |
Output is correct |
5 |
Correct |
330 ms |
688 KB |
Output is correct |
6 |
Correct |
244 ms |
940 KB |
Output is correct |
7 |
Correct |
255 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
776 KB |
Output is correct |
9 |
Correct |
2 ms |
776 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
212 ms |
768 KB |
Output is correct |
12 |
Correct |
286 ms |
684 KB |
Output is correct |
13 |
Correct |
505 ms |
684 KB |
Output is correct |
14 |
Correct |
371 ms |
684 KB |
Output is correct |
15 |
Correct |
338 ms |
684 KB |
Output is correct |
16 |
Correct |
269 ms |
684 KB |
Output is correct |
17 |
Correct |
284 ms |
684 KB |
Output is correct |
18 |
Correct |
257 ms |
1024 KB |
Output is correct |
19 |
Correct |
263 ms |
1188 KB |
Output is correct |
20 |
Correct |
264 ms |
684 KB |
Output is correct |
21 |
Correct |
24 ms |
772 KB |
Output is correct |
22 |
Correct |
42 ms |
768 KB |
Output is correct |
23 |
Correct |
45 ms |
744 KB |
Output is correct |
24 |
Correct |
3 ms |
768 KB |
Output is correct |
25 |
Correct |
2 ms |
768 KB |
Output is correct |
26 |
Correct |
1 ms |
768 KB |
Output is correct |
27 |
Correct |
1 ms |
776 KB |
Output is correct |
28 |
Correct |
0 ms |
768 KB |
Output is correct |
29 |
Correct |
282 ms |
768 KB |
Output is correct |
30 |
Correct |
264 ms |
684 KB |
Output is correct |
31 |
Correct |
322 ms |
684 KB |
Output is correct |
32 |
Correct |
305 ms |
684 KB |
Output is correct |
33 |
Correct |
270 ms |
684 KB |
Output is correct |
34 |
Correct |
174 ms |
972 KB |
Output is correct |
35 |
Correct |
233 ms |
944 KB |
Output is correct |
36 |
Correct |
255 ms |
940 KB |
Output is correct |
37 |
Correct |
262 ms |
1032 KB |
Output is correct |
38 |
Correct |
242 ms |
1020 KB |
Output is correct |
39 |
Correct |
257 ms |
932 KB |
Output is correct |
40 |
Correct |
240 ms |
764 KB |
Output is correct |
41 |
Correct |
295 ms |
1196 KB |
Output is correct |
42 |
Correct |
30 ms |
768 KB |
Output is correct |
43 |
Correct |
56 ms |
744 KB |
Output is correct |
44 |
Correct |
63 ms |
684 KB |
Output is correct |
45 |
Correct |
69 ms |
688 KB |
Output is correct |
46 |
Correct |
164 ms |
684 KB |
Output is correct |
47 |
Correct |
174 ms |
684 KB |
Output is correct |
48 |
Correct |
24 ms |
744 KB |
Output is correct |
49 |
Correct |
23 ms |
764 KB |
Output is correct |