# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
709934 | raysh07 | Stations (IOI20_stations) | C++17 | 957 ms | 932 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;
#define INF (int)1e9
const int N = 1005;
int timer = 0;
int tin[N], tout[N];
vector <int> adj[N];
int ans[N];
void dfs(int u, int par = -1, int dist = 0){
tin[u] = ++timer;
for (int v: adj[u]){
if (v != par){
dfs(v, u, dist + 1);
}
}
tout[u] = ++timer;
if (dist & 1) ans[u] = tout[u];
else ans[u] = tin[u];
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for (int i=0; i<n-1; i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0);
int ptr = -1;
set <int> st; map <int, int> comp;
for (int i=0; i<n; i++) st.insert(ans[i]);
for (auto x: st) comp[x] = ++ptr;
assert(st.size() == n);
vector <int> lab;
for (int i=0; i<n; i++) lab.push_back(comp[ans[i]]);
for (int i=0; i<n; i++) adj[i].clear();
return lab;
}
int find_next_station(int s, int t, vector<int> c) {
if (s==0){
//root
for (auto x: c){
if (x >= t) return x;
}
assert(false);
}
if (c.size() == 1) return c[0];
//either s is tin time of u, in which case, rest all are tout times
//tout of everything else shud be strictly larger
//else s is tout time of u, in which case rest all are tin times
//tin of everything else shud be strictly smaller
if (s > c[0]){
//this is tout time
//rest all are tin time
//if t is not in range [c[1], s] its not in subtree
if (t < c[1] || t > s) return c[0];
c.push_back(INF);
for (int i=2; i<c.size(); i++){
if (c[i] > t) return c[i-1];
}
}
else {
assert(s < c[0]);
//now range is [s, c[c.size() - 2]
if (t < s || t > c[c.size() - 2]) return c.back();
for (int i=0; i<c.size() - 1; i++){
if (t <= c[i]) return c[i];
}
}
}
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... |