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 <bits/stdc++.h>
#include "stations.h"
using namespace std;
vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
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> ti(n), to(n);
int T = 0;
auto DFS = [&] (auto DFS, int u, int par, int h) -> void
{
ti[u] = ++T;
for (int i = 0; i < (int)adj[u].size(); i++) {
if (adj[u][i] == par) {
adj[u].erase(adj[u].begin() + i);
break;
}
}
if (adj[u].size()) {
for (int i = 0; i < (int)adj[u].size() - 1; i++) {
DFS(DFS, adj[u][i], u, h + 1);
}
DFS(DFS, adj[u].back(), u, h + 1);
}
to[u] = ++T;
if (h & 1) labels[u] = ti[u];
else labels[u] = to[u];
};
DFS(DFS, 0, -1, 0);
return labels;
}
int find_next_station(int s, int t, vector<int> c)
{
if (s > c.back()) {
for (int i = 1; i < (int)c.size() - 1; i++) {
if (c[i] <= t && t < c[i + 1]) return c[i];
}
if (c.back() <= t && t < s) return c.back();
return c.front();
}
else {
for (int i = 1; i < (int)c.size() - 1; i++) {
if (c[i - 1] < t && t <= c[i]) return c[i];
}
if (s <= t && t <= c.front()) return c.front();
return c.back();
}
}
# | 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... |