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 <bits/stdc++.h>
#include "stations.h"
using namespace std;
const int maxn = 1002;
vector <int> ad [maxn];
int in[maxn], out [maxn];
int dp[maxn];
int ct = 0;
int get_nd (int x) {
return x / 2;
}
void dfs (int u, int p) {
in[u]=ct++;
int mx = 0;
for (int v: ad[u]) {
if (v == p) continue;
dp[v] = dp[u] + 1;
dfs(v, u);
}
out[u]=ct++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n);
vector <int> norm (n);
ct = 0;
for (int i = 0; i < n; i++){
in[i] = out[i] = dp[i] = 0;
ad[i].clear();
}
for (int i = 0; i < n - 1; i++){
ad[u[i]].push_back(v[i]);
ad[v[i]].push_back(u[i]);
}
dfs(0, -1);
for (int i = 0; i < n; i++){
if (dp[i] % 2 == 0) labels[i] = in[i];
else labels[i] = out[i];
norm[i] = labels[i];
}
sort(norm.begin(), norm.end());
for (int i = 0; i < n; i++){
labels[i] = lower_bound(norm.begin(), norm.end(), labels[i]) - norm.begin();
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if (c[0] > s) {
if (t < s) return c.back();
auto it = lower_bound(c.begin(), c.end(), t);
if (it == c.begin()) it--;
return *it;
}
if (t > s) return c[0];
auto it = upper_bound(c.begin(), c.end(), t);
if (it != c.begin()) it--;
return *it;
}
Compilation message (stderr)
stations.cpp: In function 'void dfs(int, int)':
stations.cpp:16:6: warning: unused variable 'mx' [-Wunused-variable]
16 | int mx = 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... |