# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
309353 | xt0r3 | Stations (IOI20_stations) | C++14 | 0 ms | 0 KiB |
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;
int timer;
vector<bool> f;
vector<int> l, d;
vector<vector<int> > g;
void dfs(int id, bool flag = 1){
d[id] = timer++;
f[id] = flag;
for(int v : g[id]) if(d[v] == -1) dfs(v, !flag);
l[id] = timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
f.resize(n);
l.assign(n, -1);
d.assign(n, -1);
g.assign(n, {});
for(int i = 0; i < n - 1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
timer = 0;
dfs(0);
vector<int> ret(n);
for(int i = 0; i < n; i++){
ret[i] = (f[id] ? d[id] / 2 : l[id] / 2);
}
}
int find_next_station(int s, int t, vector<int> c){
if(s < c[0]){
//c has leaving times
if(s < c.front() || s > c.back()) return c.back();
return c[(int)(lower_bound(c.begin(), c.end(), t)];
}
else{
//c has discovery times
if(s < c.front() || s > c.back()) return c.front();
return c[(int)(upper_bound(c.begin(), c.end(), t)) - 1];
}
}