# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1051490 | aykhn | Stations (IOI20_stations) | C++17 | 544 ms | 1048 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;
const int MAX = 1005;
vector<int> g[MAX];
int in[MAX], out[MAX];
int col[MAX];
int t = 0;
void dfs(int node, int p){
col[node] = col[p] ^ 1;
in[node] = t++;
for(int to : g[node]){
if(to == p) continue;
dfs(to, node);
}
out[node] = t++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for(int i = 0; i < n; i++) g[i].clear();
for(int i = 0; i < n - 1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs(1, 1);
vector<int> L;
for(int i = 0; i < n; i++){
if(col[i]) L.push_back(in[i]);
else L.push_back(out[i]);
}
return L;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(), c.end());
if(s < c[0]){
int in = s + 1;
for(int i = 0; i < c.size() - 1; i++){
if(in <= t && t <= c[i]){
return c[i];
}
in = c[i] + 1;
}
return c.back();
}
else{
sort(c.rbegin(), c.rend());
int out = s - 1;
for(int i = 0; i < c.size() - 1; i++){
if(c[i] <= t && t <= out) return c[i];
out = c[i] - 1;
}
return c.back();
}
}
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... |