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;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
int N, K, idx;
vvi adj;
vi in, out, parity;
void dfs(int v, int p)
{
in[v] = idx++;
parity[v] = parity[p] ^ 1;
for (int u : adj[v])
if (u != p)
dfs(u, v);
out[v] = idx++;
};
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v)
{
K = k;
N = n;
adj.clear();
adj.resize(N);
for (int i = 0; i < N - 1; ++i)
adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]);
idx = 0;
in.assign(N, -1), out.assign(N, -1), parity.assign(N, 0);
dfs(0, 0);
vi labels(N);
for (int i = 0; i < n; i++)
labels[i] = (parity[i]) ? in[i] : out[i];
return labels;
}
int find_next_station(int s, int t, std::vector<int> c)
{
if (s < c[0])
{
// s has in parity
if (t < s)
return c.back(); // parent with highest out value
for (int i = 0; i < sz(c); ++i)
{
if (t <= c[i])
return c[i];
}
return c.back();
}
else
{
// s has out parity
if (t > s)
return c[0];
for (int i = sz(c) - 1; i >= 0; --i)
if (t >= c[i])
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... |