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;
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<vector<int>> G(n);
vector<int> l(n), r(n), ret(n);
for(int i = 0; i < n - 1; i++) {
G[u[i]].push_back(v[i]);
G[v[i]].push_back(u[i]);
}
int cnt = -1;
function<void(int, int)> dfs = [&](int x, int p) {
l[x] = ++cnt;
for(int y : G[x]) {
if(y == p) continue;
dfs(y, x);
}
r[x] = cnt;
};
dfs(0, -1);
for(int i = 0; i < n; i++) {
ret[i] = r[i] * 1000 + l[i];
}
return ret;
}
int find_next_station(int s, int t, vector<int> c) {
int sz = c.size();
t = t % 1000;
sort(begin(c), end(c), [&](int a, int b){
int la = a % 1000; int ra = a / 1000;
int lb = b % 1000; int rb = b / 1000;
return (ra - la) < (rb - lb);
});
for(int i = 0; i < sz - 1; i++) {
int l = c[i] % 1000;
int r = c[i] / 1000;
if(l <= t && t <= r) return c[i];
}
return c[sz - 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... |