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 "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
vector <int> g[1010];
int in[1010],out[1010],dep[1010],tme;
void dfs(int cur,int prv){
if (prv==-1) dep[cur]=0;
else dep[cur]=dep[prv]+1;
in[cur]=++tme;
for (int i:g[cur]){
if (i==prv) continue;
dfs(i,cur);
}
out[cur]=++tme;
}
vector <int> label(int n,int k,vector <int> u,vector <int> v){
for (int i=0; i<n; i++) g[i].clear();
tme=-1;
for (int i=0; i<n-1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs(0,-1);
vector <int> ret(n);
for (int i=0; i<n; i++){
if (dep[i]%2==0) ret[i]=in[i];
else ret[i]=out[i];
}
vector <int> cpy=ret;
sort(cpy.begin(),cpy.end());
for (int i=0; i<n; i++) ret[i]=lower_bound(cpy.begin(),cpy.end(),ret[i])-cpy.begin();
return ret;
}
int find_next_station(int s,int t,vector <int> c){
if (c.size()==1) return c[0];
if (binary_search(c.begin(),c.end(),t)) return t;
if (s>*max_element(c.begin(),c.end())){
for (int i=1; i+1<c.size(); i++){
if (c[i]<=t&&t<c[i+1]) return c[i];
}
if (t>s||t<c[1]) return c.front();
return c.back();
}
if (!s){
for (int i=0; i<c.size(); i++){
if (t<=c[i]) return c[i];
}
}
for (int i=1; i+1<c.size(); i++){
if (c[i-1]<t&&t<=c[i]) return c[i];
}
if (t<s||t>c[c.size()-2]) return c.back();
return c.front();
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i=1; i+1<c.size(); i++){
| ~~~^~~~~~~~~
stations.cpp:48:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i=0; i<c.size(); i++){
| ~^~~~~~~~~
stations.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i=1; i+1<c.size(); 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... |