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;
const int N = 1005;
int a[N];
vector <int> g[N];
int dfs (int v, int p, int l, int h) {
if (h) {
a[v] = l;
l++;
}
int x = 0;
for (int u : g[v]) {
if (u != p) {
int w = dfs (u, v, l, 1 - h);
l += w;
x += w;
}
}
if (!h) {
a[v] = l;
l++;
}
return x + 1;
}
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();
int m = (int)u.size();
for (int i = 0; i < m; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs (0, 0, 0, 0);
vector <int> labels;
for (int i = 0; i < n; i++) {
labels.push_back (a[i]);
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if (c.size() == 1)
return c[0];
int w = 1;
if (s > c[0]) {
s = -s;
t = -t;
for (int i = 0; i < (int)c.size(); i++)
c[i] = -c[i];
w = -1;
}
sort (c.begin(), c.end());
int p = N;
if (s != 0) {
p = c.back();
c.pop_back();
}
int ft = c.back();
if (t >= s && t <= ft) {
for (int x : c) {
if (x >= t)
return x * w;
}
} else {
return p * w;
}
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:72:1: warning: control reaches end of non-void function [-Wreturn-type]
72 | }
| ^
# | 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... |