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;
#define pb push_back
vector<int> label(int n, int k, vector<int> u, vector<int> v){
int timer = 0, tin[n], tout[n], dep[n];
vector<vector<int>> g(n);
for(int i = 0; i < n-1; ++i) g[u[i]].pb(v[i]), g[v[i]].pb(u[i]);
function<void(int, int)> dfs = [&](int v, int p){
tin[v] = timer++;
dep[v] = dep[p] + 1;
for(int u: g[v]){
if(u != p) dfs(u, v);
}
tout[v] = timer++;
};
dep[0] = 0;
dfs(0, 0);
vector<int> l;
for(int i = 0; i < n; ++i) l.pb(dep[i] % 2 == 1 ? tin[i] : tout[i]);
vector<int> a = l;
sort(a.begin(), a.end());
for(int i = 0; i < n; ++i) l[i] = lower_bound(a.begin(), a.end(), l[i]) - a.begin();
return l;
}
int find_next_station(int s, int t, vector<int> c){
for(int p: c){
if(p==t) return t;
}
if(s == 0){
for(int i = 0; i < c.size(); ++i){
if(c[i] >= t){
return c[i];
}
}
assert(0);
}
if(s <= c[0]){
int par = c.back();
if(t <= s || par <= t)
return par;
for(int i = 0; i < c.size() - 1; ++i){
if(c[i] >= t){
return c[i];
}
}
}
int par = c[0];
if(t >= s || t <= par){
return par;
}
for(int i = c.size() - 1; i >= 1; --i){
if(c[i] <= t){
return c[i];
}
}
return -1;
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 0; i < c.size(); ++i){
| ~~^~~~~~~~~~
stations.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0; i < c.size() - 1; ++i){
| ~~^~~~~~~~~~~~~~
# | 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... |