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;
const int maxn = 1000;
vector<int> adjlist[maxn];
vector<int> labels;
int ct = 0;
void dfs(int cur, int par, int type) {
if (type == 0) { // preorder
labels[cur] = ct++;
for (auto a : adjlist[cur])
if (a != par) dfs(a, cur, 1);
} else {
for (auto a : adjlist[cur])
if (a != par) dfs(a, cur, 0);
labels[cur] = ct++;
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
ct = 0;
labels.clear();
for (int i = 0; i < n; i++) adjlist[i].clear();
for (int i = 0; i < n - 1; i++)
adjlist[u[i]].push_back(v[i]), adjlist[v[i]].push_back(u[i]);
labels.resize(n);
dfs(0, 0, 0);
// for (auto a : labels) cout << a << " ";
// cout << "\n";
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if (c.size() == 1) return c.front();
sort(c.begin(), c.end());
if (s > c.front()) {
if (t > s) return c.front();
return *(upper_bound(c.begin(), c.end(), t) - 1);
} else {
if (t < s) return c.back();
return *lower_bound(c.begin(), c.end(), t);
}
}
# | 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... |