#include "stations.h"
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int MX = 1042;
int in[MX];
int out[MX];
int dep[MX];
int dfsT = 0;
vector<int> adj[MX];
void dfs(int node, int par, int d) {
//cout << "cur " << node << '\n';
dep[node] = d;
if (d % 2 == 0) in[node] = dfsT++;
for (auto& x: adj[node])
if (x != par)
dfs(x, node, d + 1);
if (d % 2 == 1) out[node] = dfsT++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
//cout << "called\n";
dfsT = 0;
vector<int> labels(n);
for (int i = 0; i < n; i++)
adj[i].clear();
for (int i = 0; i + 1 < n; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, -1, 0);
for (int i = 0; i < n; i++)
labels[i] = ((dep[i] % 2) == 0) ? in[i] : out[i];
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
c.push_back(s);
sort(c.begin(), c.end());
if (c[0] == s) {
// s is tin
// the rest is tout
int par = c.back(); // par has max tout
int curIn = c[0] + 1;
for (int i = 1; i + 1 < (int)c.size(); i++) {
int inTime = curIn;
int outTime = c[i];
if (inTime <= t && t <= outTime)
return c[i];
curIn = outTime + 1;
}
return par;
} else {
// s is tout
// the rest is tin
int par = c[0];
int curOut = c.back() - 1;
for (int i = (int)c.size() - 1; i > 0; i--) {
int inTime = c[i];
int outTime = curOut;
if (inTime <= t && t <= outTime)
return c[i];
curOut = inTime - 1;
}
return par;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
529 ms |
652 KB |
Output is correct |
2 |
Correct |
460 ms |
540 KB |
Output is correct |
3 |
Correct |
855 ms |
416 KB |
Output is correct |
4 |
Correct |
614 ms |
672 KB |
Output is correct |
5 |
Correct |
602 ms |
416 KB |
Output is correct |
6 |
Correct |
441 ms |
536 KB |
Output is correct |
7 |
Correct |
431 ms |
552 KB |
Output is correct |
8 |
Correct |
2 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
496 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
502 ms |
528 KB |
Output is correct |
2 |
Correct |
499 ms |
528 KB |
Output is correct |
3 |
Correct |
753 ms |
416 KB |
Output is correct |
4 |
Correct |
752 ms |
528 KB |
Output is correct |
5 |
Correct |
588 ms |
548 KB |
Output is correct |
6 |
Correct |
449 ms |
536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
473 ms |
676 KB |
Output is correct |
2 |
Correct |
506 ms |
760 KB |
Output is correct |
3 |
Correct |
868 ms |
544 KB |
Output is correct |
4 |
Correct |
600 ms |
548 KB |
Output is correct |
5 |
Correct |
546 ms |
524 KB |
Output is correct |
6 |
Correct |
417 ms |
644 KB |
Output is correct |
7 |
Correct |
458 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
4 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
11 |
Correct |
535 ms |
532 KB |
Output is correct |
12 |
Correct |
454 ms |
760 KB |
Output is correct |
13 |
Correct |
432 ms |
772 KB |
Output is correct |
14 |
Correct |
411 ms |
548 KB |
Output is correct |
15 |
Correct |
44 ms |
572 KB |
Output is correct |
16 |
Correct |
58 ms |
740 KB |
Output is correct |
17 |
Correct |
113 ms |
672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
907 ms |
524 KB |
Output is correct |
2 |
Correct |
593 ms |
548 KB |
Output is correct |
3 |
Correct |
603 ms |
532 KB |
Output is correct |
4 |
Correct |
2 ms |
628 KB |
Output is correct |
5 |
Correct |
3 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
540 ms |
572 KB |
Output is correct |
8 |
Correct |
905 ms |
524 KB |
Output is correct |
9 |
Correct |
643 ms |
520 KB |
Output is correct |
10 |
Correct |
567 ms |
416 KB |
Output is correct |
11 |
Correct |
4 ms |
628 KB |
Output is correct |
12 |
Correct |
4 ms |
620 KB |
Output is correct |
13 |
Correct |
4 ms |
620 KB |
Output is correct |
14 |
Correct |
4 ms |
628 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
511 ms |
420 KB |
Output is correct |
17 |
Correct |
503 ms |
516 KB |
Output is correct |
18 |
Correct |
392 ms |
528 KB |
Output is correct |
19 |
Correct |
466 ms |
528 KB |
Output is correct |
20 |
Correct |
466 ms |
416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
480 ms |
660 KB |
Output is correct |
2 |
Correct |
424 ms |
652 KB |
Output is correct |
3 |
Correct |
903 ms |
520 KB |
Output is correct |
4 |
Correct |
550 ms |
572 KB |
Output is correct |
5 |
Correct |
573 ms |
420 KB |
Output is correct |
6 |
Correct |
461 ms |
656 KB |
Output is correct |
7 |
Correct |
424 ms |
520 KB |
Output is correct |
8 |
Correct |
2 ms |
628 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
628 KB |
Output is correct |
11 |
Correct |
436 ms |
544 KB |
Output is correct |
12 |
Correct |
432 ms |
548 KB |
Output is correct |
13 |
Correct |
655 ms |
524 KB |
Output is correct |
14 |
Correct |
653 ms |
548 KB |
Output is correct |
15 |
Correct |
610 ms |
528 KB |
Output is correct |
16 |
Correct |
488 ms |
548 KB |
Output is correct |
17 |
Correct |
582 ms |
548 KB |
Output is correct |
18 |
Correct |
424 ms |
644 KB |
Output is correct |
19 |
Correct |
449 ms |
772 KB |
Output is correct |
20 |
Correct |
413 ms |
544 KB |
Output is correct |
21 |
Correct |
45 ms |
572 KB |
Output is correct |
22 |
Correct |
65 ms |
748 KB |
Output is correct |
23 |
Correct |
113 ms |
768 KB |
Output is correct |
24 |
Correct |
4 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
620 KB |
Output is correct |
26 |
Correct |
4 ms |
624 KB |
Output is correct |
27 |
Correct |
3 ms |
620 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
503 ms |
544 KB |
Output is correct |
30 |
Correct |
498 ms |
544 KB |
Output is correct |
31 |
Correct |
521 ms |
420 KB |
Output is correct |
32 |
Correct |
474 ms |
420 KB |
Output is correct |
33 |
Correct |
468 ms |
548 KB |
Output is correct |
34 |
Correct |
242 ms |
664 KB |
Output is correct |
35 |
Correct |
406 ms |
792 KB |
Output is correct |
36 |
Correct |
404 ms |
768 KB |
Output is correct |
37 |
Correct |
483 ms |
620 KB |
Output is correct |
38 |
Correct |
456 ms |
756 KB |
Output is correct |
39 |
Correct |
467 ms |
768 KB |
Output is correct |
40 |
Correct |
449 ms |
672 KB |
Output is correct |
41 |
Correct |
463 ms |
656 KB |
Output is correct |
42 |
Correct |
59 ms |
676 KB |
Output is correct |
43 |
Correct |
99 ms |
672 KB |
Output is correct |
44 |
Correct |
141 ms |
548 KB |
Output is correct |
45 |
Correct |
161 ms |
548 KB |
Output is correct |
46 |
Correct |
325 ms |
544 KB |
Output is correct |
47 |
Correct |
317 ms |
548 KB |
Output is correct |
48 |
Correct |
62 ms |
696 KB |
Output is correct |
49 |
Correct |
55 ms |
856 KB |
Output is correct |