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;
int _labels[1010];
vector<int> adj[1010];
int N, K, timer = 0;
void dfs(int a, int p, int lv){
if(!lv) _labels[a] = timer++;
for(auto x : adj[a]){
if(x == p) continue;
dfs(x, a, 1 - lv);
}
if(lv) _labels[a] = timer++;
}
vector<int> label(int _N, int _K, vector<int> U, vector<int> V) {
N = _N; K = _K; timer = 0;
for(int i = 0; i < N - 1; i++){
adj[U[i]].push_back(V[i]);
adj[V[i]].push_back(U[i]);
}
dfs(0, 0, 0);
vector<int> res;
for(int i = 0; i < N; i++) res.push_back(_labels[i]);
for(int i = 0; i < N; i++) adj[i].clear();
return res;
}
int find_next_station(int S, int T, vector<int> C) {
if(C.size() == 1) return C[0];
if(C[0] > S){
int st = S;
for(int i = 0; i < C.size() - 1; i++){
if(st < T && T <= C[i]) return C[i];
st = C[i];
}
return C[C.size() - 1];
}
else{
for(int i = 1; i < C.size() - 1; i++){
if(C[i] <= T && T < C[i + 1]) return C[i];
}
if(C[C.size() - 1] <= T && T < S) return C[C.size() - 1];
return C[0];
}
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 0; i < C.size() - 1; i++){
| ~~^~~~~~~~~~~~~~
stations.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | 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... |