# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
706807 | rafatoa | Paint By Numbers (IOI16_paint) | 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 <bits/stdc++.h>
using namespace std;
vector<int> label(int n, int k, vector<int> u, vector<int> v){
vector<int> l(n);
vector<vector<int>> adj(n);
for(int i=0; i<n-1; i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
int aux = 0;
function<void(int, int, int)> dfs = [&](int s, int e, int d){
if(d%2 == 0) l[s] = aux++;
for(auto u:adj[s])
if(u != e) dfs(u, s, d+1);
if(d%2 == 1) l[s] = aux++;
};
dfs(0, -1, 0);
return l;
}
int find_next_station(int s, int t, vector<int> c){
sort(c.begin(), c.end());
int n = c.size();
if(n == 1) return c[0]; //Out of bounds
if(s < c[0]){
if(t < s || t > c[n-2]) return c[n-1];
for(int i=0; i<n; i++)
if(c[i] >= t) return c[i];
} else {
if(t > s || t < c[1]) return c[0];
for(int i=2; i<n; i++)
if(c[i] > t) return c[i-1];
return c[n-1];
}
}