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 isz(a) (int)(a).size()
const int NM = 1000;
vector <int> adj[NM+5];
int dep[NM+5];
int timer = 0, tin[NM+5], tout[NM+5];
vector <int> arr;
void dfs(int u, int p){
dep[u] = (p == -1 ? 0 : dep[p]+1);
tin[u] = ++timer;
for (int v : adj[u]){
if (v == p) continue;
dfs(v, u);
}
tout[u] = ++timer;
}
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, -1);
for (int i = 0; i < n; i++){
if (dep[i]&1) arr.push_back(tout[i]); else arr.push_back(tin[i]);
}
sort(arr.begin(), arr.end());
vector <int> ans(n);
for (int i = 0; i < n; i++){
if (dep[i]&1) ans[i] = lower_bound(arr.begin(), arr.end(), tout[i])-arr.begin();
else ans[i] = lower_bound(arr.begin(), arr.end(), tin[i])-arr.begin();
}
return ans;
}
int find_next_station(int s, int t, vector <int> c){
if (s < c.front()){
if (t < s || t > c.back()) return c.back();
for (int i = 0; i+1 < isz(c); i++)
if (c[i] >= t) return c[i];
return -1;
}
else{
if (t < c.front() || t > s) return c.front();
for (int i = isz(c)-1; i > 0; i--)
if (c[i] <= t) return c[i];
return -1;
}
}
# | 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... |