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>
#define PB push_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
using namespace std;
vector<int> g[1000];
int tin[1000], tout[1000], tt = 0, ht[1000];
void dfs(int v, int p, bool tp){
tin[v] = tt++;
ht[v] = tp;
for (int u : g[v]){
if (u == p) continue;
dfs(u, v, tp ^ 1);
}
tout[v] = tt++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
for (int i = 0; i < n; i++)
g[i].clear();
tt = 0;
for (int i = 0; i < sz(u); i++){
g[u[i]].PB(v[i]);
g[v[i]].PB(u[i]);
}
dfs(0, -1, 0);
vector<int> labels;
labels.resize(n);
for (int i = 0; i < n; i++) {
if (ht[i] == 0)
labels[i] = tin[i];
else labels[i] = tout[i] + 2000;
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
int N = 2000;
int ss = s;
if (s >= N) ss -= N;
int tt = t;
if (t >= N) tt -= N;
if (s < N){
if (ss > tt) return c.back();
int siz = sz(c);
int lst = c.back() - N;
if (s > 0) {
if (sz(c) > 1)
lst = c[siz - 2] - N;
else lst = -1;
}
if (tt <= lst){
for (int v : c)
if (tt <= v - N)
return v;
} else return c.back();
} else {
if (ss < tt) return c[0];
if (sz(c) > 1 && tt >= c[1]){
reverse(all(c));
for (int v : c)
if (tt >= v)
return v;
} else return c[0];
}
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:88:1: warning: control reaches end of non-void function [-Wreturn-type]
88 | }
| ^
# | 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... |