# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
591642 | Morisz10 | Stations (IOI20_stations) | C++14 | 0 ms | 0 KiB |
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>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 1000;
vector<int> g[maxn];
int l;
vector<int> labels, max_label, r_label;
int dfs(int x, int p) {
max_label[x] = labels[x] = l++;
r_label[labels[x]] = x;
for (int i : g[x]) {
if (i != p)max_label[x] = dfs(i, x);
}
return max_label[x];
}
vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
labels.assign(n, 0);
for (int i = 0; i < n; i++)g[i] = {};
max_label = labels;
r_label = labels;
for (int i = 0; i < u.size(); i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
l = 0;
dfs(0, -1);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
for (int i = 0; i < c.size() - 1; i++) {
if (t < c[i + 1])return c[i];
}
return t > max_label[r_label[c.back()]] ? c[0] : c.back();
}
int main() {
int n, k;
cin >> n >> k;
vector<int> u(n - 1), v(n - 1);
for (int i = 0; i < n - 1; i++) {
cin >> u[i] >> v[i];
}
label(n, k, u, v);
}