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 <bits/stdc++.h>
#include "stations.h"
using namespace std;
typedef long long ll;
void dfs(vector<vector<int>> &adj, int n, int id, int prev, int &val, vector<int> &res, int layer) {
if (!(layer & 1)) {
res[id] += val++;
}
for (auto &e : adj[id]) {
if (e == prev) continue;
dfs(adj, n, e, id, val, res, layer + 1);
}
if (layer & 1) {
res[id] += val++;
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<vector<int>> adj(n);
for (ll i = 0; i < n-1; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
vector<int> res(n, 0);
int val = 0;
dfs(adj, n, 0, -1, val, res, 0);
return res;
}
int find_next_station(int s, int t, vector<int> c) {
if (c.size() == 1) return c[0];
if (s == 0) {
for (ll i = 0; i <= c.size() - 1; i++) {
if (c[i] >= t) return c[i];
}
}
bool end = s > c[0];
if (end) {
ll parent = c[0];
ll a = c[1];
if (t < a || t > s) return parent;
for (ll i = c.size() - 1; i >= 1; i--) {
if (c[i] <= t) return c[i];
}
}
else {
ll parent = c.back();
ll b = c[c.size() - 2];
if (t < s || t > b) return parent;
for (ll i = 0; i <= c.size() - 2; i++) {
if (c[i] >= t) return c[i];
}
}
return -1;
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:37:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (ll i = 0; i <= c.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~~
stations.cpp:54:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (ll i = 0; i <= c.size() - 2; i++) {
| ~~^~~~~~~~~~~~~~~
# | 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... |