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;
#define ll long long
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define vf first
#define vs second
const int N = 1003;
vector<int> adj[N];
int col[N],tin[N] , tout[N] , timer;
void dfs(int node ,int par ,int c){
col[node] = c;
int c_next = (c + 1)%2;
tin[node] = timer++;
for(int i : adj[node]){
if(i != par){
dfs(i , node , c_next);
}
}
tout[node] = timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
for(int i = 0; i < n - 1; i++){
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
timer=0;
dfs(0,0,0);
vector<int> labels(n);
for(int i = 0; i < n; i++){
if(col[i] == 0)labels[i] = tin[i];
else labels[i] = tout[i];
}
map<int,int> m;
for(int i = 0; i < n; i++){
m[labels[i]] = 1;
}
int val[2 * n + 5];
int cur = 0;
for(auto i : m){
val[i.vf] = cur++;
}
for(int i = 0; i < n; i++){
labels[i] = val[labels[i]];
//cout << labels[i] << ' ';
}
for(int i = 0; i <= n; i++){
adj[i].clear();
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
sort(all(c));
if(s == 0){
int prev = 0;
for(int i : c){
if(t >= prev && t <= i){
return i;
}
}
}
else {
int col;
if(c[0] > s){
col = 0;
}
else col = 1;
int par;
if(col == 0){
par = c.back();
}
else par = c[0];
if(col == 0){
int prev = s;
for(int i = 0; i < c.size()-1; i++){
if(t >= s && t <= c[i]){
return c[i];
}
prev = c[i] + 1;
}
return par;
}
else {
for(int i = 1; i < c.size()-1; i++){
if(t >= c[i] && t < c[i + 1]){
return c[i];
}
}
if(t >= c.back() && t <= s){
return c.back();
}
return par;
}
}
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:92:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for(int i = 0; i < c.size()-1; i++){
| ~~^~~~~~~~~~~~
stations.cpp:91:8: warning: variable 'prev' set but not used [-Wunused-but-set-variable]
91 | int prev = s;
| ^~~~
stations.cpp:101:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int i = 1; i < c.size()-1; i++){
| ~~^~~~~~~~~~~~
stations.cpp:112:1: warning: control reaches end of non-void function [-Wreturn-type]
112 | }
| ^
# | 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... |