# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085300 | 4QT0R | Stations (IOI20_stations) | C++17 | 3062 ms | 2097152 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> graph[1002];
int dep[1002];
int timer;
int pre[1002];
int post[1002];
void dfs(int v, int p){
pre[v]=timer++;
for (auto u : graph[v]){
if (u==p)continue;
dep[u]=dep[v]+1;
dfs(u,v);
}
post[v]=timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
for (int i = 0; i<n-1; i++){
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
dfs(0,-1);
int iter=0;
set<int> s;
map<int,int> mp;
for (int i = 0; i<n; i++)s.insert(dep[i]&1?post[i]:pre[i]);
for (auto x : s)mp[x]=iter++;
vector<int> ans(n);
for (int i = 0; i<n; i++){
ans[i]=mp[dep[i]&1?post[i]:pre[i]];
}
return ans;
}
int find_next_station(int s, int t, vector<int> c){
int cas=1;
for (auto u : c)if (s<u)cas=0;
if (cas){
int fat=c[0];
c.erase(c.begin());
int prv=s;
for (int i = c.size()-1; i>=0; i--){
if (c[i]<=t && t<prv)return c[i];
prv=c[i];
}
return fat;
}
else{
int fat=c.back();
c.pop_back();
int prv=s;
for (int i = 0; i<c.size(); i++){
if (prv<t && t<=c[i])return c[i];
prv=c[i];
}
return fat;
}
}
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... |