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>
using namespace std;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
vector<int> labels(n);
vector<vector<int>> adj(n);
for(int i=0;i<n-1;i++){
adj[u[i]].emplace_back(v[i]);
adj[v[i]].emplace_back(u[i]);
}
int tim = 0;
function<void(int,int,bool)> dfs = [&](int x,int p,bool type){
if(type)labels[x]=tim++;
for(int&i:adj[x])if(i!=p)dfs(i,x,!type);
if(!type)labels[x]=tim++;
};
dfs(0,-1,true);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s<c.front()){
// this is a min order
c.insert(c.begin(),s);
for(int i=1;i<c.size();i++){
if(c[i-1]<t and t<=c[i])return c[i];
}
return c.back();
} else {
// this is a max order
c.insert(c.end(),s);
for(int i=0;i<c.size()-1;i++){
if(c[i]<=t and t<c[i+1])return c[i];
}
return c.front();
}
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:25:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i=1;i<c.size();i++){
| ~^~~~~~~~~
stations.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i=0;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... |