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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int nextnum;
int arr[1005];
vector<int> pairs[1005];
void dfs(int par, int a, int dep){
if(dep%2){
arr[a] = nextnum;
nextnum++;
}
for(int i:pairs[a]){
if(i!=par){
dfs(a,i,dep+1);
}
}
if(dep%2==0){
arr[a] = nextnum;
nextnum++;
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
nextnum = 0;
for(int i=0;i<n-1;i++){
pairs[u[i]].push_back(v[i]);
pairs[v[i]].push_back(u[i]);
}
dfs(-1,0,1);
vector<int> ans;
for(int i=0;i<n;i++){
ans.push_back(arr[i]);
}
return ans;
}
int find_next_station(int s, int t, vector<int> c){
sort(c.begin(),c.end());
if(s==0){
for(int i:c){
if(t<=i){
return i;
}
}
}
else if(c.size()==1){
return c[0];
}
else{
if(c[0]<s){
if(s<t){
return c[0];
}
reverse(c.begin(),c.end());
for(int i=0;i<c.size()-1;i++){
if(c[i]<=t){
return c[i];
}
}
return c[c.size()-1];
}
else{
if(s>t){
return c[c.size()-1];
}
for(int i=0;i<c.size()-1;i++){
if(c[i]>=t){
return c[i];
}
}
return c[c.size()-1];
}
}
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:58:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i=0;i<c.size()-1;i++){
| ~^~~~~~~~~~~
stations.cpp:69:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i=0;i<c.size()-1;i++){
| ~^~~~~~~~~~~
stations.cpp:77:1: warning: control reaches end of non-void function [-Wreturn-type]
77 | }
| ^
# | 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... |