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>
#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(iter(a), greater<>())
#define eb emplace_back
#define ef emplace_front
#define pob pop_back()
#define pof pop_front()
#define mp make_pair
#define F first
#define S second
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
typedef long long ll;
typedef long double ld;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.F << ',' << p.S << ')';
}
const int N = 2000;
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<vector<int>> g(n);
vector<int> ans(n);
int ts = -1;
function<void(int, int, int)> dfs = [&](int now, int p, int d){
int in = ++ts;
for(int i : g[now]){
if(i == p) continue;
dfs(i, now, d + 1);
}
int out = ++ts;
if(d % 2 == 0) ans[now] = in;
else ans[now] = N + out;
};
for(int i = 0; i < n - 1; i++){
g[u[i]].eb(v[i]);
g[v[i]].eb(u[i]);
}
for(int i = 0; i < n; i++){
if(g[i].size() > 1) continue;
dfs(i, i, 0);
break;
}
//cerr << "label ";
//printv(ans, cerr);
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
if(c.size() == 1) return c[0];
//cerr << "find " << s << " " << t << " : ";
//printv(c, cerr);
int tmp = t >= N ? t - N : t;
//cerr << "tmp " << tmp << "\n";
if(s < N){
int in = s;
for(int i = 0; i < (int)c.size() - 1; i++){
int a = i == 0 ? in + 1 : c[i - 1] - N + 1;
int b = c[i] - N;
//cerr << "test " << i << " " << a << " " << b << "\n";
if(a <= tmp && tmp <= b) return c[i];
}
return c.back();
}
else{
int out = s - N;
for(int i = 1; i < (int)c.size(); i++){
int a = c[i];
int b = i == (int)c.size() - 1 ? out : c[i + 1] - 1;
//cerr << "test " << i << " " << a << " " << b << "\n";
if(a <= tmp && tmp <= b) return c[i];
}
return c[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... |