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;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
vector<vector<int>> adj(n);
for (int i = 0; i < n - 1; ++i) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
vector<int> in(n), out(n);
int dtime = -1;
auto dfs = [&](auto self, int u, int p) -> void {
in[u] = ++dtime;
for (int v : adj[u]) if (v != p) {
self(self, v, u);
}
out[u] = dtime;
};
dfs(dfs, 0, -1);
for (int i = 0; i < n; i++) {
labels[i] = in[i] * 1000 + out[i];
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
int res = -1;
int inS = s / 1000;
int inT = t / 1000;
int parS = 0;
for (int x : c) {
int i = x / 1000, j = x % 1000;
if (i <= inT && inT <= j)
res = x;
if (i <= inS && inS <= j)
parS = x;
}
if (res == -1)
res = parS;
return res;
}
# | 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... |