#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
vector<int> labels(n, -1);
vector<vector<int>> adj(n);
for (int i = 0; i < n-1; ++i)
{
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
int ctr = 0;
function<void(int, int, int)> dfs = [&](int node, int par, int h)
{
if (h & 1) labels[node] = ctr++; //in
for (int to : adj[node])
if (to != par)
dfs(to, node, h+1);
if (~h & 1) labels[node] = ctr++; //out
};
dfs(0, -1, 1);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(c.begin(), c.end());
if (c.back() < s) //s is out
{
c.pb(s);
for (int i = (int)c.size() - 2; i >= 1; --i)
{
if (c[i] <= t && t < c[i+1])
return c[i];
}
return c[0];
}
else // s in in
{
c.pb(s); sort(c.begin(), c.end());
for (int i = 0; i+1 < (int)c.size(); ++i)
{
if (c[i] < t && t <= c[i+1])
return c[i+1];
}
return c.back();
}
return c[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
575 ms |
640 KB |
Output is correct |
2 |
Correct |
595 ms |
656 KB |
Output is correct |
3 |
Correct |
1039 ms |
400 KB |
Output is correct |
4 |
Correct |
871 ms |
424 KB |
Output is correct |
5 |
Correct |
601 ms |
488 KB |
Output is correct |
6 |
Correct |
516 ms |
520 KB |
Output is correct |
7 |
Correct |
530 ms |
520 KB |
Output is correct |
8 |
Correct |
3 ms |
476 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
528 ms |
476 KB |
Output is correct |
2 |
Correct |
495 ms |
488 KB |
Output is correct |
3 |
Correct |
989 ms |
400 KB |
Output is correct |
4 |
Correct |
805 ms |
528 KB |
Output is correct |
5 |
Correct |
611 ms |
400 KB |
Output is correct |
6 |
Correct |
590 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
685 ms |
620 KB |
Output is correct |
2 |
Correct |
511 ms |
608 KB |
Output is correct |
3 |
Correct |
1121 ms |
484 KB |
Output is correct |
4 |
Correct |
892 ms |
488 KB |
Output is correct |
5 |
Correct |
731 ms |
400 KB |
Output is correct |
6 |
Correct |
575 ms |
608 KB |
Output is correct |
7 |
Correct |
560 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
484 KB |
Output is correct |
9 |
Correct |
7 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
583 ms |
488 KB |
Output is correct |
12 |
Correct |
531 ms |
732 KB |
Output is correct |
13 |
Correct |
586 ms |
724 KB |
Output is correct |
14 |
Correct |
515 ms |
492 KB |
Output is correct |
15 |
Correct |
76 ms |
404 KB |
Output is correct |
16 |
Correct |
68 ms |
528 KB |
Output is correct |
17 |
Correct |
149 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
990 ms |
524 KB |
Output is correct |
2 |
Correct |
813 ms |
400 KB |
Output is correct |
3 |
Correct |
690 ms |
400 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
476 KB |
Output is correct |
6 |
Correct |
2 ms |
476 KB |
Output is correct |
7 |
Correct |
765 ms |
476 KB |
Output is correct |
8 |
Correct |
1047 ms |
400 KB |
Output is correct |
9 |
Correct |
810 ms |
400 KB |
Output is correct |
10 |
Correct |
632 ms |
400 KB |
Output is correct |
11 |
Correct |
7 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
555 ms |
400 KB |
Output is correct |
17 |
Correct |
579 ms |
528 KB |
Output is correct |
18 |
Correct |
618 ms |
492 KB |
Output is correct |
19 |
Correct |
640 ms |
400 KB |
Output is correct |
20 |
Correct |
507 ms |
404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
623 ms |
656 KB |
Output is correct |
2 |
Correct |
452 ms |
640 KB |
Output is correct |
3 |
Correct |
951 ms |
400 KB |
Output is correct |
4 |
Correct |
748 ms |
492 KB |
Output is correct |
5 |
Correct |
734 ms |
484 KB |
Output is correct |
6 |
Correct |
594 ms |
656 KB |
Output is correct |
7 |
Correct |
540 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
640 ms |
496 KB |
Output is correct |
12 |
Correct |
620 ms |
528 KB |
Output is correct |
13 |
Correct |
1033 ms |
476 KB |
Output is correct |
14 |
Correct |
779 ms |
488 KB |
Output is correct |
15 |
Correct |
745 ms |
528 KB |
Output is correct |
16 |
Correct |
524 ms |
488 KB |
Output is correct |
17 |
Correct |
703 ms |
404 KB |
Output is correct |
18 |
Correct |
527 ms |
604 KB |
Output is correct |
19 |
Correct |
587 ms |
692 KB |
Output is correct |
20 |
Correct |
589 ms |
528 KB |
Output is correct |
21 |
Correct |
76 ms |
468 KB |
Output is correct |
22 |
Correct |
92 ms |
528 KB |
Output is correct |
23 |
Correct |
126 ms |
544 KB |
Output is correct |
24 |
Correct |
7 ms |
420 KB |
Output is correct |
25 |
Correct |
7 ms |
468 KB |
Output is correct |
26 |
Correct |
6 ms |
468 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
617 ms |
400 KB |
Output is correct |
30 |
Correct |
597 ms |
400 KB |
Output is correct |
31 |
Correct |
575 ms |
400 KB |
Output is correct |
32 |
Correct |
589 ms |
516 KB |
Output is correct |
33 |
Correct |
637 ms |
400 KB |
Output is correct |
34 |
Correct |
375 ms |
612 KB |
Output is correct |
35 |
Correct |
536 ms |
744 KB |
Output is correct |
36 |
Correct |
516 ms |
696 KB |
Output is correct |
37 |
Correct |
503 ms |
732 KB |
Output is correct |
38 |
Correct |
544 ms |
780 KB |
Output is correct |
39 |
Correct |
576 ms |
612 KB |
Output is correct |
40 |
Correct |
506 ms |
588 KB |
Output is correct |
41 |
Correct |
479 ms |
812 KB |
Output is correct |
42 |
Correct |
69 ms |
736 KB |
Output is correct |
43 |
Correct |
127 ms |
572 KB |
Output is correct |
44 |
Correct |
189 ms |
528 KB |
Output is correct |
45 |
Correct |
235 ms |
528 KB |
Output is correct |
46 |
Correct |
410 ms |
528 KB |
Output is correct |
47 |
Correct |
384 ms |
528 KB |
Output is correct |
48 |
Correct |
80 ms |
676 KB |
Output is correct |
49 |
Correct |
66 ms |
668 KB |
Output is correct |