# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
757657 | 1bin | 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>
#include "stations.h"
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1005;
int t, L[NMAX];
vector<int> adj[NMAX];
void dfs(int x, int p, int f){
if(!f) L[x] = t++;
for(int&nx : adj[x])
if(nx != p) dfs(nx, x, !f);
if(f) labels[x] = t++;
return;
}
vector<int>label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n);
for(int i = 0; i < n - 1; i++){
adj[u[i]].emplace_back(v[i]);
adj[v[i]].emplace_back(u[i]);
}
t = 0;
dfs(0, -1, 0);
for(int i = 0; i < n; i++) {
labels[i] = L[i];
adj[i].clear();
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
int sz = c.size();
if(s < c[0]){
for(int i = 0; i < sz; i++){
int l = !i ? s : c[i - 1] + 1, r = c[i];
if(t >= l && t <= r) return c[i];
}
return c.back();
}
else{
for(int i = 1; i < sz; i++){
int l = c[i], r = (i == sz - 1 ? s - 1: c[i + 1] - 1);
if(t >= l && t <= r) return c[i];
}
return c[0];
}
}