# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
660167 | evenvalue | Stations (IOI20_stations) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;
using int64 = long long;
using ld = long double;
constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e15 + 10;
constexpr int kMod = 1e9 + 7;
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
vector<int> depth(n);
vector<int> tin(n, -1), tout(n, -1);
function<int(int, int)> dfs = [&](int x, int p)-> int {
int time = tin[x] + 1;
for (const int y : g[x]) {
if (y == p) continue;
tin[y] = time;
depth[y] = 1 - depth[x];
time = dfs(y, x) + 1;
}
return tout[x] = time;
};
depth[0] = 0;
tin[0] = tout[0] = 0;
dfs(0, -1);
vector<int> labels(n);
for (int x = 0; x < n; x++) {
labels[x] = (depth[x] == 0 ? tin[x] : tout[x]);
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
// if (c[0] > s) {
sort(c.begin(), c.end());
for (int i = 0; i < c.size() - 1; i++) {
if (s < t and t <= c[i]) return c[i];
}
return c.back();
// } else {
// sort(c.rbegin(), c.rend());
// for (int i = 0; i < c.size() - 1; i++) {
// if (c[i] <= t and s < t) return c[i];
// }
// return c.back();
}
}