#include <bits/stdc++.h>
struct Node {
std::vector <int> nei;
int id, d, a, b;
Node() : id(0), d(0), a(0), b(0) { }
};
struct Triplet {
int x, y, z;
Triplet(int X = 0, int Y = 0, int Z = 0) : x(X), y(Y), z(Z) { }
bool operator<(const Triplet& other) const {
if (x == other.x) return y > other.y;
return x < other.x;
}
};
void dfs(std::vector <Node>& g, int node = 0, int par = -1) {
static int cnt = 0;
g[node].a = cnt++;
g[node].d = par == -1 ? 0 : g[par].d + 1;
for (int x : g[node].nei) if (x != par) dfs(g, x, node);
g[node].b = cnt - 1;
}
std::vector <int> label(int n, int k, std::vector <int> u, std::vector <int> v) {
std::vector <int> r(n);
std::vector <Node> g(n);
for (int i = 0; i < n; i++) g[i].id = i;
for (int i = 0; i < n - 1; i++) {
g[u[i]].nei.push_back(v[i]);
g[v[i]].nei.push_back(u[i]);
}
dfs(g);
std::vector <Triplet> tr(n);
for (int i = 0; i < n; i++) tr[i] = Triplet(g[i].d & 1 ? g[i].b : g[i].a, g[i].d, i);
std::sort(tr.begin(), tr.end());
for (int i = 0; i < n; i++) r[tr[i].z] = i;
return r;
}
int find_next_station(int s, int t, std::vector <int> c) {
if (!(c.size() - 1)) return c.front();
if (!s) for (int x : c) if (x >= t) return x;
if (s < c.front()) {
if (!(s <= t && t <= c[c.size() - 2])) return c.back();
for (int x : c) if (x >= t) return x;
}
if (!(s <= t && c[1] <= t)) return c.front();
for (int i = (int)c.size() - 1; i >= 0; i--) if (t >= c[i]) return c[i];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
683 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
633 ms |
884 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
655 ms |
1016 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1142 ms |
640 KB |
Output is correct |
2 |
Incorrect |
844 ms |
640 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
669 ms |
1064 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |