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 all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
//#define int long long
template <class _T>
bool chmin(_T &x, const _T &y){
bool flag = false;
if ( x > y ){
x = y; flag |= true;
}
return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
bool flag = false;
if ( x < y ){
x = y; flag |= true;
}
return flag;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector <int> g[n], d(n, -1), tin(n), tout(n);
for ( int i = 0; i + 1 < n; i++ ){
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
}
vector <int> ans(n);
int timer = 1;
d[0] = 0;
function <void(int)> dfs = [&](int x){
tin[x] = timer++;
for ( auto to: g[x] ){
if ( d[to] == -1 ){
d[to] = d[x] + 1;
dfs(to);
}
}
tout[x] = timer++;
if ( !(d[x] & 1) ){
ans[x] = tin[x];
} else ans[x] = tout[x];
}; dfs(0);
vector <int> pos(n);
iota(all(pos), 0);
sort(all(pos), [&](int &x, int &y){
return ans[x] < ans[y];
});
vector <int> f(n);
for ( int i = 0; i < n; i++ ){
f[pos[i]] = i;
}
return f;
}
int find_next_station(int s, int t, vector<int> c) {
int n = (int)c.size();
if ( c.back() < s ){
for ( int i = n - 1; i > 0; i-- ){
if ( c[i] <= t and s >= t ){
return c[i];
}
}
return c[0];
}
for ( int i = 0; i + 1 < n; i++ ){
if ( c[i] >= t and s <= t ){
return c[i];
}
}
return c.back();
}
# | 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... |