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;
int lo, hi = -1;
vector<int> L, R;
vector<bool> flor;
void dfs(int s, int p, bool flr) {
flor[s] = flr;
bool leaf = 1;
L[s] = 0x3f3f3f3f;
R[s] = -0x3f3f3f3f;
for(auto& u : adj[s]) {
if(u == p) continue;
leaf = 0;
dfs(u, s, flr ^ 1);
L[s] = min(L[s], L[u]);
R[s] = max(R[s], R[u]);
}
if(leaf) {
++hi;
L[s] = R[s] = hi;
} else {
if(flr) {
++hi;
R[s] = hi;
} else {
--lo;
L[s] = lo;
}
}
}
vector<int> label(int N, int K, vector<int> u, vector<int> v) {
flor.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] = (flor[i] ? R[i] - lo: L[i] - lo);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if(s == 0) {
pair<int, int> T = {t, t};
vector<pair<int, int>> C((int)c.size());
C[0] = {1, c[0]};
for(int i = 1; i < (int)c.size(); ++i) {
C[i] = {c[i - 1] + 1, c[i]};
}
for(int i = 0; i < (int)c.size(); ++i) {
if(C[i].first <= T.second && C[i].second >= T.second) return c[i];
}
}
if(s < c[0]) {
pair<int, int> S = {s, c.back() - 1}, T = {t, t};
vector<pair<int, int>> C((int)c.size());
C[0] = {s + 1, c[0]};
C.back() = {s, c.back()};
for(int i = 1; i + 1 < (int)c.size(); ++i) {
C[i] = {c[i - 1] + 1, c[i]};
}
for(int i = 0; i + 1 < (int)c.size(); ++i) {
if(C[i].first <= T.second && C[i].second >= T.second) return c[i];
}
return c.back();
}
pair<int, int> S = {c[0] + 1, s}, T = {t, t};
vector<pair<int, int>> C((int)c.size());
C.back() = {c.back(), s - 1};
C[0] = {c[0], s};
for(int i = 1; i + 1 < (int)c.size(); ++i) {
C[i] = {c[i], c[i + 1] - 1};
}
for(int i = 1; i < (int)c.size(); ++i) {
if(C[i].first <= T.second && C[i].second >= T.second) return c[i];
}
return c[0];
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:65:18: warning: variable 'S' set but not used [-Wunused-but-set-variable]
65 | pair<int, int> S = {s, c.back() - 1}, T = {t, t};
| ^
stations.cpp:77:17: warning: variable 'S' set but not used [-Wunused-but-set-variable]
77 | pair<int, int> S = {c[0] + 1, s}, T = {t, t};
| ^
# | 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... |