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;
#define ll long long
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
template<typename T>
int len(T &a){return a.size();}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<vector<int>> g(n);
for(int i = 0; i < n - 1;i ++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
vector<int> tin(n), tout(n);
int tim = 0;
auto dfs = [&](auto &dfs, int i, int p = -1)->void{
tin[i] = tim ++;
for(auto u : g[i]){
if(u == p) continue;
dfs(dfs, u, i);
}
tout[i] = tim - 1;
};
dfs(dfs, 0);
vector<int> res(n);
for(int i = 0; i < n; i ++){
res[i] = tin[i] * 1000 + tout[i];
}
return res;
}
int find_next_station(int s, int t, vector<int> c) {
if(len(c) == 1) return c[0];
for(auto u : c){
if(t == u) return u;
}
int sin = s / 1000, sout = s % 1000;
int tin = t / 1000, tout = t % 1000;
if(tin < sin || tout > sout){
return c[0];
}
for(int i = (sin ? 1 : 0); i < len(c); i ++){
int u = c[i];
if(tout <= u % 1000){
return u;
}
}
assert(0);
}
# | 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... |