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;
#define all(a) a.begin(), a.end()
vector<int>Vis, new_;
vector<vector<int>>A;
bool even;
int time_;
void dfs(int ind){
Vis[ind]=1;
bool odd=!even;
if(!odd)
new_[ind]=time_++;
for(int i=0;i<A[ind].size();i++)
if(!Vis[A[ind][i]]){
even=odd;
dfs(A[ind][i]);
}
if(odd) new_[ind]=time_++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
Vis.clear(), A.clear(), new_.clear();
Vis.resize(n), A.resize(n), new_.resize(n);
time_=0, even=1;
for(int i=0;i<n-1;i++)
A[u[i]].push_back(v[i]), A[v[i]].push_back(u[i]);
dfs(0);
return new_;
}
int find_next_station(int s, int t, vector<int> c) {
if(c[0]<s){
if(t>s) return c.front();
for(int i=c.size()-1;i>=0;i--)
if(c[i]<=t)
return c[i];
}
else{
if(t<s) return c.back();
for(int i=0;i<c.size();i++)
if(c[i]>=t)
return c[i];
}
}
Compilation message (stderr)
stations.cpp: In function 'void dfs(int)':
stations.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i=0;i<A[ind].size();i++)
| ~^~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<c.size();i++)
| ~^~~~~~~~~
stations.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
42 | }
| ^
# | 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... |