#include "stations.h"
#include <algorithm>
#include <vector>
using namespace std;
vector<vector<int>> g;
vector<int> intime, outtime, depth;
int time;
void dfs(int v) {
intime[v] = time++;
for (int x : g[v])
if (intime[x] == -1) {
depth[x] = depth[v] + 1;
dfs(x);
}
outtime[v] = time++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
g.assign(n, {});
intime.assign(n, -1);
outtime.assign(n, -1);
depth.assign(n, 0);
for (int i = 0; i < n - 1; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
time = 0;
dfs(0);
vector<int> labels(n);
for (int i = 0; i < n; i++) {
labels[i] = depth[i] % 2 == 0 ? intime[i] / 2 : outtime[i] / 2;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
// sort(c.begin(), c.end()); they are already sorted
if (s < c[0]) {
// s: intime, c[i]: outtime, c.back(): parent of s
// subtree of s: s < t <= c[c.size() - 2]
if (t < s || c.size() == 1 || t > c[c.size() - 2])
return c.back();
return *(upper_bound(c.begin(), c.end(), t) - 1);
} else {
// s: outtime, c[i]: intime, c[0]: parent of s
// subtree of s: c[1] <= t < s
if (t > s || c.size() == 1 || t < c[1])
return c[0];
return *lower_bound(c.begin(), c.end(), t);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
547 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
482 ms |
792 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
522 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
921 ms |
640 KB |
Output is correct |
2 |
Correct |
660 ms |
640 KB |
Output is correct |
3 |
Incorrect |
799 ms |
640 KB |
Wrong query response. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
614 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |