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>
using namespace std;
int ti;
vector<int> adj[1005];
void dfs(int u, int p, int d, vector<int> &labels) {
if (d % 2 == 0)
labels[u] = ti++;
for (int v : adj[u])
if (v != p)
dfs(v, u, d + 1, labels);
if (d % 2 == 1)
labels[u] = ti++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
ti = 0;
for (int i=0; i<n; i++)
adj[i].clear();
for (int i=0; i<n-1; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, -1, 0, labels);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if (c.back() < s) {
// odd depth
if (t > s || t < c[0])
return c[0];
for (int i=0; i<(int)c.size()-1; i++)
if (t >= c[i] && t < c[i+1])
return c[i];
return c.back();
} else {
// even depth
if (t < s || t > c.back())
return c.back();
for (int i=(int)c.size()-1; i>0; i--)
if (t <= c[i] && t > c[i-1])
return c[i];
return c[0];
}
}
# | 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... |