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 <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;
const int maxn = 1e3 + 5;
vector<int> g[maxn];
int tin[maxn], tout[maxn], t = 0;
vector<int> l;
void dfs(int u, int d, int p = -1)
{
if (!d) l[u] = tin[u] = t++;
for (int v : g[u]) if (v != p) dfs(v, d ^ 1, u);
if (d) l[u] = tout[u] = t++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
t = 0;
for (int i = 0; i < n; i++) g[i].clear(), tin[i] = tout[i] = 0;
for (int i = 0; i < n - 1; i++) g[u[i]].push_back(v[i]), g[v[i]].push_back(u[i]);
l.assign(n, 0);
dfs(0, 0);
return l;
}
int find_next_station(int s, int t, vector<int> c)
{
int k = c.size();
if (s <= c[0]) // ja som tin, c-cka su tout
{
int tin = s;
int tout = (s ? (k > 1 ? c[k - 2] : s) : c[k - 1]);
if (t < tin || t > tout) return c[k - 1]; // v tomto podstrome nie je t, musim ist do rodica
int i = 0;
while (c[i] < t) i++;
return c[i];
}
else // ja som tout, c-cka su tin
{
int tin = (k > 1 ? c[1] : s);
int tout = s;
if (t < tin || t > tout) return c[0]; // v tomto podstrome nie je t, musim ist do rodica
int i = 0;
while (i + 1 < k && c[i + 1] <= t) i++;
return c[i];
}
}
# | 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... |