# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
594543 | snasibov05 | Stations (IOI20_stations) | C++14 | 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;
int tm = 0;
void dfs(int cur, int pr, vector<int>& tin, vector<int>& tout, vector<int>& d, vector<vector<int>>& ed) {
tin[cur] = tm++;
d[cur] = d[pr] + 1;
for (auto to : ed[cur]) {
if (to == pr) continue;
dfs(to, cur, tin, tout, d, ed);
}
tout[cur] = tm++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<vector<int>> ed(n);
for (int i = 0; i < n-1; ++i) {
ed[u[i]].push_back(v[i]);
ed[v[i]].push_back(u[i]);
}
vector<int> d(n), tin(n), tout(n);
tm = 0, d[0] = -1;
dfs(0, 0, tin, tout, d, ed);
vector<int> label(n);
for (int i = 0; i < n; ++i){
if (d[i] % 2 == 0) label[i] = tin[i];
else label[i] = tout[i];
}
return label;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(), c.end());
if (s < c[0]){
int prev = s;
for (int i = 0; i < c.size() - 1; ++i){
if (prev <= t && t <= c[i]) return c[i];
prev = c[i];
}
return c.back();
} else{
int prev = s;
for (int i = c.size() - 1; i > 0; --i){
if (c[i] <= t && t <= prev) return c[i];
prev = c[i];
}
return c[0];
}
}