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>
using namespace std;
vector<vector<int>> adj;
vector<int> L, R, sz;
void dfs(int s, int p, int low) {
L[s] = low;
sz[s] = 1;
for(auto& u : adj[s]) {
if(u == p) continue;
dfs(u, s, low + sz[s] - 1);
sz[s] += sz[u];
}
R[s] = low + sz[s] - 1;
}
pair<int, int> conv(int s) {
return {s % 1000, s / 1000};
}
int conv(pair<int, int> s) {
return s.first + s.second * 1000;
}
vector<int> label(int N, int K, vector<int> u, vector<int> v) {
sz.resize(N);
L.resize(N);
R.resize(N);
adj.resize(N);
for(auto& I : adj) I.clear();
for(int i = 0; i < (int)u.size(); ++i) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, -1, 0);
vector<int> labels(N);
for(int i = 0; i < N; ++i) labels[i] = conv({L[i], R[i]});
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
pair<int, int> S = conv(s), T = conv(t);
vector<pair<int, int>> C((int)c.size());
for(int i = 0; i < (int)c.size(); ++i) C[i] = conv(c[i]);
int par = -1, ans = -1;
for(int i = 0; i < (int)c.size(); ++i) {
if(C[i].first <= S.first && C[i].second >= S.second) par = i;
else if(C[i].first <= T.second && C[i].second >= T.second) ans = i;
}
return (ans == -1 ? conv(C[par]) : conv(C[ans]));
}
# | 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... |