# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1073765 | thatsgonzalez | Stations (IOI20_stations) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define s second
#define f first
vector <int> sub_tree;
vector <int> labels;
int mx , mn;
int dfs(int node, int p){
for(auto &x: g[node]){
if(x == node) continue;
sub_tree[node]+=dfs(x,node);
}
return sub_tree[node]=sub_tree[node]+1;
}
void calc_labels(int node, int p, int t){
if(t){
labels[node] = mn+sub_tree[node]-1;
}
else{
labels[node] = mn; mn++;
}
for(auto &x: g[node]){
if(x == p) continue;
calc_labels(x,node,t^1);
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
sub_tree.assign(n,0);
dfs(0,-1);
mn = 1;
calc_labels(0,-1,1);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c[0]>s){
int l = s;
for(int i = 0; i<c.size()-1; i++){
if(t>=l and t<=c[i]){
return c[i];
}
else l = c[i]+1;
}
return c.back();
}
else{
int r = s;
for(int i = c.size()-1; i; i--){
if(t>=c[i] and t<=r) return c[i];
else r = c[i]-1;
}
return c[0];
}
}