#include "stations.h"
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
namespace lab {
vector<vector<int>> g;
vector<int> tin, tout, d;
int timer;
void dfs(int v, int p) {
timer += d[v]%2 == 0;
tin[v] = timer;
for(auto &i : g[v]) if(i != p) {
d[i] = d[v]+1;
dfs(i, v);
}
timer += d[v]%2 == 1;
tout[v] = timer;
}
};
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
using namespace lab;
timer = -1;
tin = tout = d = vector<int>(n);
g.assign(n, vector<int>());
for(int i = 0; i+1 < n; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs(0, 0);
std::vector<int> labels(n);
for (int i = 0; i < n; i++) {
labels[i] = (d[i]&1) ? tout[i] : tin[i];
}
return labels;
}
int rv(int a) { return a; }
int find_next_station(int s, int t, std::vector<int> c) {
int type, par;
type = s > *max_element(all(c));//tout
if(s) {
if(type == 0) {//tin here, tout in neighbors
par = *max_element(all(c));
c.erase(max_element(all(c)));
} else {//tout here
par = *min_element(all(c));
c.erase(min_element(all(c)));
}
} else par = -1;
if(!type) {
if(rv(t) < rv(s)) return par;
int mn = 1<<30;
for(auto &i : c) if(rv(t) <= rv(i)) mn = min(mn, i);
if(mn == 1<<30) mn = par;
return mn;
}
if(t > s) return par;
int mx = -1;
for(auto &i : c) if(rv(t) >= rv(i)) mx = max(mx, i);
if(mx == -1) mx = par;
return mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
549 ms |
1024 KB |
Output is correct |
2 |
Correct |
464 ms |
1024 KB |
Output is correct |
3 |
Correct |
879 ms |
644 KB |
Output is correct |
4 |
Correct |
668 ms |
644 KB |
Output is correct |
5 |
Correct |
600 ms |
652 KB |
Output is correct |
6 |
Correct |
476 ms |
1024 KB |
Output is correct |
7 |
Correct |
467 ms |
784 KB |
Output is correct |
8 |
Correct |
2 ms |
656 KB |
Output is correct |
9 |
Correct |
4 ms |
656 KB |
Output is correct |
10 |
Correct |
1 ms |
656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
487 ms |
1000 KB |
Output is correct |
2 |
Correct |
517 ms |
812 KB |
Output is correct |
3 |
Correct |
1063 ms |
640 KB |
Output is correct |
4 |
Correct |
722 ms |
640 KB |
Output is correct |
5 |
Correct |
666 ms |
772 KB |
Output is correct |
6 |
Correct |
473 ms |
828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
655 ms |
1160 KB |
Output is correct |
2 |
Correct |
450 ms |
1024 KB |
Output is correct |
3 |
Correct |
873 ms |
640 KB |
Output is correct |
4 |
Correct |
642 ms |
640 KB |
Output is correct |
5 |
Correct |
633 ms |
784 KB |
Output is correct |
6 |
Correct |
526 ms |
1024 KB |
Output is correct |
7 |
Correct |
479 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
644 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
641 ms |
640 KB |
Output is correct |
12 |
Correct |
552 ms |
1136 KB |
Output is correct |
13 |
Correct |
488 ms |
1128 KB |
Output is correct |
14 |
Correct |
443 ms |
812 KB |
Output is correct |
15 |
Correct |
65 ms |
896 KB |
Output is correct |
16 |
Correct |
74 ms |
848 KB |
Output is correct |
17 |
Correct |
109 ms |
800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
880 ms |
644 KB |
Output is correct |
2 |
Correct |
674 ms |
644 KB |
Output is correct |
3 |
Correct |
563 ms |
648 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
777 ms |
644 KB |
Output is correct |
8 |
Correct |
882 ms |
652 KB |
Output is correct |
9 |
Correct |
662 ms |
896 KB |
Output is correct |
10 |
Correct |
581 ms |
644 KB |
Output is correct |
11 |
Correct |
7 ms |
656 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
644 KB |
Output is correct |
14 |
Correct |
5 ms |
644 KB |
Output is correct |
15 |
Correct |
2 ms |
780 KB |
Output is correct |
16 |
Correct |
540 ms |
896 KB |
Output is correct |
17 |
Correct |
525 ms |
784 KB |
Output is correct |
18 |
Correct |
509 ms |
640 KB |
Output is correct |
19 |
Correct |
497 ms |
788 KB |
Output is correct |
20 |
Correct |
590 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
513 ms |
1024 KB |
Output is correct |
2 |
Correct |
460 ms |
1024 KB |
Output is correct |
3 |
Correct |
908 ms |
648 KB |
Output is correct |
4 |
Correct |
714 ms |
648 KB |
Output is correct |
5 |
Correct |
618 ms |
640 KB |
Output is correct |
6 |
Correct |
517 ms |
1024 KB |
Output is correct |
7 |
Correct |
521 ms |
780 KB |
Output is correct |
8 |
Correct |
3 ms |
652 KB |
Output is correct |
9 |
Correct |
4 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
618 ms |
1032 KB |
Output is correct |
12 |
Correct |
592 ms |
824 KB |
Output is correct |
13 |
Correct |
1049 ms |
648 KB |
Output is correct |
14 |
Correct |
689 ms |
644 KB |
Output is correct |
15 |
Correct |
618 ms |
768 KB |
Output is correct |
16 |
Correct |
488 ms |
816 KB |
Output is correct |
17 |
Correct |
588 ms |
640 KB |
Output is correct |
18 |
Correct |
473 ms |
768 KB |
Output is correct |
19 |
Correct |
476 ms |
1024 KB |
Output is correct |
20 |
Correct |
453 ms |
816 KB |
Output is correct |
21 |
Correct |
61 ms |
768 KB |
Output is correct |
22 |
Correct |
74 ms |
844 KB |
Output is correct |
23 |
Correct |
109 ms |
808 KB |
Output is correct |
24 |
Correct |
6 ms |
640 KB |
Output is correct |
25 |
Correct |
6 ms |
640 KB |
Output is correct |
26 |
Correct |
5 ms |
644 KB |
Output is correct |
27 |
Correct |
4 ms |
644 KB |
Output is correct |
28 |
Correct |
2 ms |
640 KB |
Output is correct |
29 |
Correct |
516 ms |
640 KB |
Output is correct |
30 |
Correct |
581 ms |
648 KB |
Output is correct |
31 |
Correct |
510 ms |
640 KB |
Output is correct |
32 |
Correct |
492 ms |
640 KB |
Output is correct |
33 |
Correct |
523 ms |
648 KB |
Output is correct |
34 |
Correct |
318 ms |
1112 KB |
Output is correct |
35 |
Correct |
442 ms |
1024 KB |
Output is correct |
36 |
Correct |
460 ms |
1092 KB |
Output is correct |
37 |
Correct |
519 ms |
1008 KB |
Output is correct |
38 |
Correct |
481 ms |
1024 KB |
Output is correct |
39 |
Correct |
534 ms |
1008 KB |
Output is correct |
40 |
Correct |
429 ms |
1024 KB |
Output is correct |
41 |
Correct |
479 ms |
896 KB |
Output is correct |
42 |
Correct |
80 ms |
820 KB |
Output is correct |
43 |
Correct |
129 ms |
832 KB |
Output is correct |
44 |
Correct |
143 ms |
768 KB |
Output is correct |
45 |
Correct |
164 ms |
788 KB |
Output is correct |
46 |
Correct |
295 ms |
820 KB |
Output is correct |
47 |
Correct |
313 ms |
768 KB |
Output is correct |
48 |
Correct |
69 ms |
1028 KB |
Output is correct |
49 |
Correct |
66 ms |
1024 KB |
Output is correct |