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>
#define endl "\n"
using namespace std;
void dfs(int head, int par, vector<vector<int>> &tree, int &col, vector<int> &labels, int d){
if(d){
labels[head] = col ++;
}
for(int i : tree[head]){
if(i != par){
dfs(i, head, tree, col, labels, d ^ 1);
}
}
if(!d){
labels[head] = col++;
}
}
int find_next_station(int s, int t, vector<int> labels){
sort(labels.begin(), labels.end());
if(s <= labels[0]){
if(t <= s){
return labels.back();
}
for(int i : labels){
if(i >= t){
return t;
}
}
}
else{
if(t >= s){
return labels[0];
}
reverse(labels.begin(), labels.end());
for(int i : labels){
if(i <= t){
return i;
}
}
}
}
vector<int> label(int N, int K, vector<int> U, vector<int> V){
vector<vector<int>> tree(N);
for(int i = 0; i < N-1; i ++){
tree[U[i]].push_back(V[i]);
tree[V[i]].push_back(U[i]);
}
vector<int> labels(N);
int col = 0;
dfs(0, -1, tree, col, labels, 0);
return labels;
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:40:1: warning: control reaches end of non-void function [-Wreturn-type]
40 | }
| ^
# | 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... |