#include <bits/stdc++.h>
#include "stations.h"
struct Node {
std::vector <int> nei;
int d, a, b;
Node() : 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;
}
};
int cnt;
void dfs(std::vector <Node>& g, int node = 0, int par = -1) {
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) {
cnt = 0;
std::vector <int> r(n);
std::vector <Node> g(n);
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 (t <= x) return x;
if (s < c.front()) {
if (!(s <= t && t <= c[c.size() - 2])) return c.back();
for (int x : c) if (t <= x) return x;
}
if (!(s <= t && c[1] <= t)) return c.front();
for (int i = (int)c.size() - 1; i >= 0; i--) if (c[i] <= t) return c[i];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
716 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
505 ms |
888 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
690 ms |
1012 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1196 ms |
760 KB |
Output is correct |
2 |
Incorrect |
1004 ms |
640 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
670 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |