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>
#define N 1005
using namespace std;
vector<int> tree[N];
int dfs(int nd, int par, int cur, bool pre, vector<int> &labels) {
if (pre) labels[nd] = cur++;
for (int child : tree[nd]) {
if (child == par) continue;
cur = dfs(child, nd, cur, !pre, labels);
}
if (!pre) labels[nd] = cur++;
return cur;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for (int i=0; i<n; i++) tree[i].clear();
for (int i=0; i<u.size(); i++) {
tree[u[i]].push_back(v[i]);
tree[v[i]].push_back(u[i]);
}
vector<int> labels(n);
dfs(0, -1, 0, 0, labels);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(), c.end());
int sz = c.size();
if (s == t) return s;
if (sz == 1) return c[0];
if (s < c[0]) { // s is preorder
if (t < s || t > c[sz-2]) return c[sz-1]; // parent
for (int i=0; i<sz; i++) {
if (t <= c[i]) return c[i];
}
} else { // s is postorder
if (t < c[1] || t > s) return c[0]; // parent
for (int i=2; i<sz; i++) {
if (t < c[i]) return c[i-1];
}
return c[sz-1];
}
return -1337; // it should not come here
}
Compilation message (stderr)
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:22:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i=0; i<u.size(); 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... |