#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int N = (int)1e3;
int tin[N],tout[N];
int timer = 0;
vector<int> g[N];
int id[N];
int d[N];
int c = 0;
vector<int> labels;
mt19937 rnd(time(nullptr));
int sz[N];
vector<int> values;
void dfs(int v,int pr = -1){
tin[v] = timer++;
for(auto& to : g[v]){
if(to == pr) continue;
if(id[v] == 0)
id[to] = ++c;
else
id[to] = id[v];
d[to] = d[v] + 1;
dfs(to,v);
}
tout[v] = timer++;
if(d[v] % 2 == 0){
values.push_back(tin[v]);
} else {
values.push_back(tout[v]);
}
return;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
for(int i = 0; i < n; i++) g[i].clear();
timer = 0;
labels.clear();
labels.resize(n);
memset(id,0,sizeof id);
memset(d,0,sizeof d);
c = 0;
for(int i = 0; i < n-1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
values.clear();
d[0] = 0;
dfs(0);
sort(values.begin(),values.end());
values.erase(unique(values.begin(),values.end()),values.end());
for(int i = 0; i < n; i++){
if(d[i] % 2 == 0){
labels[i] = lower_bound(values.begin(),values.end(),tin[i]) - values.begin();
} else {
labels[i] = lower_bound(values.begin(),values.end(),tout[i]) - values.begin();
}
}
return labels;
}
bool upper(int a,int b){
return tin[a] <= tin[b] && tout[a] >= tout[b];
}
int find_next_station(int s, int t, std::vector<int> c) {
int tinS = 2*N, toutS = -1, tinT = 2*N, toutT = -1;
bool isToutS = true;
for(auto& to : c){
isToutS &= s > to;
}
if(isToutS)
toutS = s;
else
tinS = s;
tinT = toutT = t;
int pr = -1;
for(auto& to : c){
int in,out;
if(!isToutS){
out = to;
if(pr == -1 || out > pr)
pr = to;
}
else{
in = to;
if(pr == -1 || in < pr)
pr = to;
}
}
int go = -1;
for(auto& to : c){
// if(to == pr) continue;
int in,out;
if(!isToutS){
out = to;
if(tinT < tinS)
return pr;
if(out >= tinT && (go == -1 || out < go))
go = to;
}
else{
in = to;
if(toutT > toutS)
return pr;
if(in <= toutT && (go == -1 || in > go))
go = to;
}
}
if(go == -1)
return pr;
return go;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
493 ms |
796 KB |
Output is correct |
2 |
Correct |
440 ms |
792 KB |
Output is correct |
3 |
Correct |
869 ms |
664 KB |
Output is correct |
4 |
Correct |
488 ms |
668 KB |
Output is correct |
5 |
Correct |
424 ms |
668 KB |
Output is correct |
6 |
Correct |
313 ms |
876 KB |
Output is correct |
7 |
Correct |
396 ms |
800 KB |
Output is correct |
8 |
Correct |
1 ms |
748 KB |
Output is correct |
9 |
Correct |
2 ms |
756 KB |
Output is correct |
10 |
Correct |
0 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
375 ms |
824 KB |
Output is correct |
2 |
Correct |
345 ms |
704 KB |
Output is correct |
3 |
Correct |
842 ms |
668 KB |
Output is correct |
4 |
Correct |
568 ms |
672 KB |
Output is correct |
5 |
Correct |
445 ms |
696 KB |
Output is correct |
6 |
Correct |
329 ms |
664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
393 ms |
800 KB |
Output is correct |
2 |
Correct |
392 ms |
792 KB |
Output is correct |
3 |
Correct |
632 ms |
668 KB |
Output is correct |
4 |
Correct |
693 ms |
664 KB |
Output is correct |
5 |
Correct |
429 ms |
676 KB |
Output is correct |
6 |
Correct |
387 ms |
804 KB |
Output is correct |
7 |
Correct |
339 ms |
940 KB |
Output is correct |
8 |
Correct |
2 ms |
748 KB |
Output is correct |
9 |
Correct |
3 ms |
748 KB |
Output is correct |
10 |
Correct |
0 ms |
748 KB |
Output is correct |
11 |
Correct |
385 ms |
804 KB |
Output is correct |
12 |
Correct |
335 ms |
916 KB |
Output is correct |
13 |
Correct |
345 ms |
820 KB |
Output is correct |
14 |
Correct |
306 ms |
668 KB |
Output is correct |
15 |
Correct |
43 ms |
748 KB |
Output is correct |
16 |
Correct |
71 ms |
672 KB |
Output is correct |
17 |
Correct |
62 ms |
672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
579 ms |
672 KB |
Output is correct |
2 |
Correct |
461 ms |
664 KB |
Output is correct |
3 |
Correct |
417 ms |
800 KB |
Output is correct |
4 |
Correct |
1 ms |
760 KB |
Output is correct |
5 |
Correct |
3 ms |
748 KB |
Output is correct |
6 |
Correct |
1 ms |
748 KB |
Output is correct |
7 |
Correct |
484 ms |
672 KB |
Output is correct |
8 |
Correct |
589 ms |
668 KB |
Output is correct |
9 |
Correct |
680 ms |
668 KB |
Output is correct |
10 |
Correct |
523 ms |
720 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
5 ms |
692 KB |
Output is correct |
13 |
Correct |
3 ms |
744 KB |
Output is correct |
14 |
Correct |
3 ms |
748 KB |
Output is correct |
15 |
Correct |
1 ms |
748 KB |
Output is correct |
16 |
Correct |
465 ms |
672 KB |
Output is correct |
17 |
Correct |
440 ms |
676 KB |
Output is correct |
18 |
Correct |
349 ms |
676 KB |
Output is correct |
19 |
Correct |
376 ms |
672 KB |
Output is correct |
20 |
Correct |
302 ms |
676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
425 ms |
824 KB |
Output is correct |
2 |
Correct |
331 ms |
800 KB |
Output is correct |
3 |
Correct |
523 ms |
660 KB |
Output is correct |
4 |
Correct |
637 ms |
672 KB |
Output is correct |
5 |
Correct |
395 ms |
736 KB |
Output is correct |
6 |
Correct |
285 ms |
672 KB |
Output is correct |
7 |
Correct |
408 ms |
672 KB |
Output is correct |
8 |
Correct |
1 ms |
748 KB |
Output is correct |
9 |
Correct |
3 ms |
748 KB |
Output is correct |
10 |
Correct |
0 ms |
748 KB |
Output is correct |
11 |
Correct |
305 ms |
688 KB |
Output is correct |
12 |
Correct |
361 ms |
672 KB |
Output is correct |
13 |
Correct |
583 ms |
668 KB |
Output is correct |
14 |
Correct |
470 ms |
676 KB |
Output is correct |
15 |
Correct |
396 ms |
668 KB |
Output is correct |
16 |
Correct |
346 ms |
676 KB |
Output is correct |
17 |
Correct |
529 ms |
676 KB |
Output is correct |
18 |
Correct |
439 ms |
796 KB |
Output is correct |
19 |
Correct |
432 ms |
796 KB |
Output is correct |
20 |
Correct |
285 ms |
676 KB |
Output is correct |
21 |
Correct |
34 ms |
748 KB |
Output is correct |
22 |
Correct |
64 ms |
728 KB |
Output is correct |
23 |
Correct |
54 ms |
672 KB |
Output is correct |
24 |
Correct |
3 ms |
756 KB |
Output is correct |
25 |
Correct |
5 ms |
760 KB |
Output is correct |
26 |
Correct |
2 ms |
748 KB |
Output is correct |
27 |
Correct |
1 ms |
756 KB |
Output is correct |
28 |
Correct |
1 ms |
748 KB |
Output is correct |
29 |
Correct |
446 ms |
668 KB |
Output is correct |
30 |
Correct |
481 ms |
672 KB |
Output is correct |
31 |
Correct |
353 ms |
676 KB |
Output is correct |
32 |
Correct |
325 ms |
672 KB |
Output is correct |
33 |
Correct |
321 ms |
672 KB |
Output is correct |
34 |
Correct |
263 ms |
800 KB |
Output is correct |
35 |
Correct |
302 ms |
804 KB |
Output is correct |
36 |
Correct |
253 ms |
796 KB |
Output is correct |
37 |
Correct |
421 ms |
792 KB |
Output is correct |
38 |
Correct |
262 ms |
668 KB |
Output is correct |
39 |
Correct |
418 ms |
744 KB |
Output is correct |
40 |
Correct |
294 ms |
672 KB |
Output is correct |
41 |
Correct |
343 ms |
736 KB |
Output is correct |
42 |
Correct |
49 ms |
812 KB |
Output is correct |
43 |
Correct |
74 ms |
664 KB |
Output is correct |
44 |
Correct |
119 ms |
676 KB |
Output is correct |
45 |
Correct |
103 ms |
672 KB |
Output is correct |
46 |
Correct |
268 ms |
672 KB |
Output is correct |
47 |
Correct |
192 ms |
812 KB |
Output is correct |
48 |
Correct |
39 ms |
844 KB |
Output is correct |
49 |
Correct |
45 ms |
792 KB |
Output is correct |