| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1045278 | n1k | Stations (IOI20_stations) | C++17 | 498 ms | 944 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 <vector>
#include <bits/stdc++.h>
using namespace std;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
vector<vector<int>> g(n);
for(int i=0; i+1<n; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
vector<int> l(n);
int t = 0;
function<void(int, int, int)> dfs = [&](int u, int d, int p){
if(d%2==0){
l[u]=t++;
}
for(int v:g[u]){
if(v==p){
continue;
}
dfs(v, d+1, u);
}
if(d%2==1){
l[u]=t++;
}
};
dfs(0, 0, -1);
return l;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c.size()==1){
return c[0];
}
if(c.back()<s){
// saved time is tout
// check if we hold it
int tin = c[0], tout = s;
if(not (tin < t and t <= tout)){
return c[0];
}
for(int i=1; i<c.size(); i++){
tin = c[i], tout = (i+1 < c.size() ? c[i+1] : s);
if(tin <= t and t < tout){
return c[i];
}
}
// we hold it if tin <= t < tout or s == 0
// if not go to par
}else{
int tin = s, tout = c[c.size()-2];
if(s!=0 and not (tin <= t and t <= tout)){
return c.back();
}
if(s!=0){
c.pop_back();
}
for(int i=0; i<c.size(); i++){
tin = (i-1>=0 ? c[i-1] : s), tout = c[i];
if(tin < t and t <= tout){
return c[i];
}
}
assert(false);
}
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
