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>
using namespace std;
vector<int> st, en, d;
vector<vector<int>> adj;
int t;
void dfs(int curr, int par) {
st[curr] = t++;
for(int next : adj[curr]) {
if(next == par) continue;
d[next] = d[curr] + 1;
dfs(next, curr);
}
en[curr] = t++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
adj.clear(), st.clear(), en.clear(), d.clear();
adj.resize(n);
st.resize(n);
en.resize(n);
d.resize(n);
for(int i = 0; i < n - 1; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
vector<int> ans(n);
t = 0;
dfs(0, -1);
for(int i = 0; i < n; i++) {
if(d[i] % 2 == 0) ans[i] = st[i] / 2;
else ans[i] = en[i] / 2;
}
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
if(c[0] < s) {
for(int i = (int) c.size() - 1; i >= 1; i--) {
if(t >= c[i] && t <= s) return c[i];
}
return c[0];
}
else {
for(int i = 0; i < (int) c.size() - 1; i++) {
if(t <= c[i] && t >= s) return c[i];
}
return c.back();
}
return -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... |