# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
307380 | arthur_nascimento | 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 "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define debug
#define maxn 1010
int ini[maxn];
int fim[maxn];
int h[maxn];
vector<int> L[maxn];
int cur = 0;
void dfs(int x,int p=-1){
debug("dfs %d\n",x);
ini[x] = cur++;
for(int i : L[x])
if(i != p){
h[i] = 1 + h[x];
dfs(i,x);
}
//fim[x] = cur++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
cur = 0;
for(int i=0;i<n;i++)
L[i].clear(), h[i] = ini[i] = fim[i] = 0;
for(int i=0;i<n-1;i++){
L[u[i]].pb(v[i]);
L[v[i]].pb(u[i]);
}
for(int i=0;i<n;i++){
if(L[i].size() == 1){
dfs(i);
break;
}
vector<int> ret;
for(int i=0;i<n;i++){
if(h[i]%2 == 0)
ret.pb(ini[i]);
else
ret.pb(ini[i]);
}
for(int i : ret)
debug("%d ",i);
debug("\n");
return ret;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(t > s) return s+1;
else return s-1;
debug("qr %d %d ~",s,t); for(int i : c) debug("%d ",i); debug("\n");
if(c.size() == 1) return c[0];
sort(c.begin(), c.end());
if(s < c[0]){
// S é entrada, c[i] é saida
int pai = c[c.size()-1];
if(t < s) return pai;
if(c.size() >= 2 && t > c[c.size()-2]) return pai;
for(int i=0;i<c.size();i++){
if(t <= c[i])
return c[i];
}
}
else {
// S é saida, c[i] é entrada
int pai = c[0];
if(t > s) return pai;
if(t < c[1]) return pai;
for(int i=1;i<c.size()-1;i++){
if(t < c[i+1]) return c[i];
}
return c[c.size()-1];
}
}