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;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cerr << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 1e3 + 10;
int n, h[maxn], val[maxn], tme;
vector<int> g[maxn];
void dfs(int v, int p = -1){
if (h[v] % 2 == 0) val[v] = ++tme;
for (auto u: g[v]){
if (u != p){
h[u] = h[v] + 1;
dfs(u, v);
}
}
if (h[v] & 1) val[v] = ++tme;
//debug(v, val[v]);
}
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();
}
tme = 0;
for (int i = 0; i < n-1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
h[0] = 0;
dfs(0);
vector<int> res;
for (int i = 0; i < n; i++){
res.push_back(val[i]);
}
return res;
}
int find_next_station(int s, int t, std::vector<int> c) {
if (c.size() == 1) return c[0];
if (s < c[0]){
if (s < t && t <= c[0]) return c[0];
for (int i = 1; i < c.size()-1; i++){
if (c[i-1] < t && t <= c[i]) return c[i];
}
return c.back();
}
if (c.back() <= t && t < s) return c.back();
for (int i = c.size()-2; i; i--){
if (c[i] <= t && t < c[i+1]) return c[i];
}
return c[0];
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:62:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int i = 1; i < c.size()-1; 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... |