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;
vector<vector<int>> g;
int cnt;
vector<int> labels;
void dfs(int u, int par, bool b){
if(b) labels[u] = cnt++;
for(int v : g[u]){
if(v == par) continue;
dfs(v, u, !b);
}
if(!b) labels[u] = cnt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
cnt = 0;
g.clear();
g.resize(n);
for(int i = 0; i < n-1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
labels.assign(n, -1);
dfs(0, -1, true);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
int n = (int)c.size();
if(s < c[0]){ // IN node
if(t < s) return c[n-1];
for(int i = 0; i < n-1; i++){
if(t <= c[i]) return c[i];
}
return c[n-1];
}
else{
if(t > s) return c[0];
for(int i = n-1; i > 0; i--){
if(c[i] <= t) return c[i];
}
return c[0];
}
}
# | 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... |