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<bits/stdc++.h>
using namespace std;
int cnt;
vector<vector<int>> g;
vector<int> in, out, d;
void dfs(int cur, int dep){
if (d[cur] != -1) return;
d[cur] = dep;
in[cur] = cnt++;
for (int next : g[cur]) dfs(next, dep+1);
out[cur] = cnt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
g.resize(n);
for (int i=0; i<n-1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
in.resize(n); out.resize(n); d.resize(n, -1);
cnt = 0;
dfs(0, 0);
vector<int> l(n);
for (int i=0; i<n; i++){
if (d[i] % 2) l[i] = out[i];
else l[i] = in[i];
}
vector<int> w = l;
sort(w.begin(), w.end());
unordered_map<int,int> m;
for (int i=1; i<n; i++){
m[w[i]] = w[i-1]+1;
w[i] = w[i-1]+1;
}
for (int i=0; i<n; i++) l[i] = m[l[i]];
return l;
}
int find_next_station(int s, int t, vector<int> c){
if (c.size() == 0) return c[0];
if (s == 0){
vector<int> d(c.size());
for (int i=0; i<c.size(); i++){
if (i == 0) d[i] = s+1;
else d[i] = c[i-1]+1;
if (d[i] <= t && t <= c[i]) return c[i];
}
}
else {
int x = 2000;
for (int y : c) x = min(x, y);
if (s < x){
vector<int> d(c.size()-1);
for (int i=0; i<c.size()-1; i++){
if (i == 0) d[i] = s+1;
else d[i] = c[i-1]+1;
if (d[i] <= t && t <= c[i]) return c[i];
}
return c.back();
}
else {
vector<int> d(c.size());
for (int i=c.size()-1; i>=0; i--){
if (i == c.size()-1) d[i] = s-1;
else d[i] = c[i+1]-1;
if (c[i] <= t && t <= d[i]) return c[i];
}
return c[0];
}
}
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i=0; i<c.size(); i++){
| ~^~~~~~~~~
stations.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i=0; i<c.size()-1; i++){
| ~^~~~~~~~~~~
stations.cpp:67:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | if (i == c.size()-1) d[i] = s-1;
| ~~^~~~~~~~~~~~~
stations.cpp:74:1: warning: control reaches end of non-void function [-Wreturn-type]
74 | }
| ^
# | 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... |