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;
vector<pair<int, int>> prepost;
vector<vector<int>> cons;
int C = 0;
void dfs(int i, int from){
prepost[i].first = C++;
for (int c : cons[i]){
if (c == from) continue;
dfs(c, i);
}
prepost[i].second = C;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n);
cons.resize(n);
for (int i = 0; i < n - 1; ++i) {
cons[u[i]].push_back(v[i]);
cons[v[i]].push_back(u[i]);
}
int l = -1;
for (int i = 0; i < n; ++i) if (cons[i].size() == 1) l = i;
prepost.resize(n);
dfs(l, -1);
for (int i = 0; i < n; ++i) {
labels[i] = prepost[i].first;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if (c.size() == 1) return c[0];
if (s < t) return max(c[0], c[1]);
return min(c[0], c[1]);
}
# | 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... |