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>
#include "stations.h"
using namespace std;
void dfs(int curr , int par , int hi , vector<vector<int>> &graph , int &cnt , vector<int> &ret){
if(hi%2 == 0){
ret[curr] = cnt;
cnt += 1;
}
for(auto i : graph[curr]){
if(i == par){
continue;
}
dfs(i,curr,hi+1,graph,cnt,ret);
}
if(hi%2 == 1){
ret[curr] = cnt;
cnt += 1;
}
}
vector<int> label(int n , int k , vector<int> u , vector<int> v){
vector<vector<int>> graph(1001);
int cnt = 0;
for(int i = 0 ; i < u.size() ; i += 1){
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
vector<int> labels(n);
dfs(0,0,0,graph,cnt,labels);
return labels;
}
int find_next_station(int s , int t , vector<int> c){
sort(c.begin(),c.end());
if(c.size() == 1){
return c[0];
}
if(s < c[0]){
if(t >= s && t <= c[c.size()-2]){
for(int i = 0 ; i < c.size() ; i += 1){
if(t <= c[i]){
return c[i];
}
}
}
return c.back();
}else{
if(t <= s && t >= c[1]){
for(int i = c.size()-1 ; i >= 0 ; i -= 1){
if(t >= c[i]){
return c[i];
}
}
}
return c[0];
}
}
Compilation message (stderr)
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0 ; i < u.size() ; i += 1){
| ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:41:22: 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 = 0 ; i < c.size() ; i += 1){
| ~~^~~~~~~~~~
# | 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... |