# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
373949 | Jarif_Rahman | Stations (IOI20_stations) | C++17 | 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>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
vector<vector<int>> v;
vector<int> lb, sz;
int in = 0;
void dfs(int nd, int ss, int d){
if(d%2 == 0) lb[nd] = in;
in++;
for(int x: v[nd]) if(x != ss) dfs(x, nd, d+1);
if(d%2 == 1) lb[nd] = in;
in++
}
vector<int> label(int n, int k, vector<int> aa, vector<int> bb){
in = 0;
v.assign(n, {});
lb.assign(n, -1);
for(int i = 0; i < n-1; i++){
v[aa[i]].pb(bb[i]);
v[bb[i]].pb(aa[i]);
}
dfs(0, -1);
return lb;
}
int find_next_station(int s, int t, vector<int> c){
sort(c.begin(), c.end());
if(s > c[0]){
c.pb(s);
for(int i = 1; i < (int)c.size() - 1; i++){
if(t >= c[i] && t < c[i+1]) return c[i];
}
return c[0];
}
else{
reverse(c.begin(). c.end());
c.pb(s);
for(int i = (s==0); i < (int)c.size()-1; i++){
if(t <= c[i] && t > c[i+1]) return c[i];
}
return c[0];
}
}