# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
781061 | kamelfanger83 | Stations (IOI20_stations) | C++14 | 762 ms | 708 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 <vector>
#include <cassert>
#define int long long
using namespace std;
vector<pair<int, int>> prepost;
vector<vector<int>> cons;
int C = 0;
void dfs(int i, int from){
prepost[i].first = C++;
for (int c : cons[i]){
if (c == from) continue;
dfs(c, i);
}
prepost[i].second = C - 1;
}
vector<signed> label(signed n, signed k, vector<signed> u, vector<signed> v) {
vector<signed> labels(n);
cons.clear();
cons.resize(n);
for (int i = 0; i < n - 1; ++i) {
cons[u[i]].push_back(v[i]);
cons[v[i]].push_back(u[i]);
}
prepost.clear();
prepost.resize(n);
C = 0;
dfs(0, -1);
for (int i = 0; i < n; ++i) {
labels[i] = prepost[i].first * 1000 + prepost[i].second;
}
return labels;
}
signed find_next_station(signed s, signed t, vector<signed> c) {
int spre = s / 1000, spost = s % 1000;
int tpre = t / 1000, tpost = t % 1000;
bool isdes = spre < tpre && tpost <= spost;
for (int i = 0; i < c.size(); ++i) {
int cpre = c[i] / 1000, cpost = c[i] % 1000;
if (cpre < spre && spost <= cpost){
if (!isdes) return c[i];
}
else if (cpre <= tpre && tpost <= cpost){
assert(isdes);
return c[i];
}
}
//assert(false);
//return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |