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 <iostream>
#include <climits>
#include <algorithm>
using namespace std;
int dfs(vector<int> &labels, vector<vector<int>> &tree, int v, int p, int pre, int d){
if(d&1)
labels[v] = pre;
for(auto i : tree[v]){
if(i!=p){
pre = dfs(labels, tree, i, v, pre+1, d+1);
}
}
if(!(d&1))
labels[v] = pre;
return pre+1;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
vector<vector<int>> tree(n);
for(int i = 0; i < u.size(); i++){
tree[u[i]].push_back(v[i]);
tree[v[i]].push_back(u[i]);
}
dfs(labels, tree, 0, -1, 0, 0);
std::cerr << "LOG ";
for(auto i : labels) std::cerr << i << ' ';
std::cerr << "\n";
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
for(auto i : c) if(i == t) return t;
vector<int> pre(c.size()-1), post(c.size()-1);
sort(c.begin(), c.end());
int minn = INT_MAX, parent = 0;
for(auto i : c) minn = min(i, minn);
if(minn < s){
parent = c[0];
c.erase(c.begin());
for(int i = 0; i < c.size(); i++) pre[i] = c[i];
post.back() = s-1;
for(int i = 0; i < c.size()-1; i++){
post[i] = pre[i+1]-1;
}
}else{
parent = c.back();
c.pop_back();
for(int i = 0; i < c.size(); i++) post[i] = c[i];
pre[0] = s+1;
for(int i = 1; i < c.size(); i++){
pre[i] = post[i-1];
}
}
cerr <<"S: " << s << " T: " << t << "\nPRE: ";
for(auto i : pre) cerr << i << ' ';
cerr << "\nPOST: ";
for(auto i : post) cerr << i << ' ';
cerr << '\n';
for(int i = 0; i < c.size(); i++){
if(t>=pre[i] && t <= post[i]) parent = c[i];
}
return parent;
}
Compilation message (stderr)
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i = 0; i < u.size(); i++){
| ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i = 0; i < c.size(); i++) pre[i] = c[i];
| ~~^~~~~~~~~~
stations.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i = 0; i < c.size()-1; i++){
| ~~^~~~~~~~~~~~
stations.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i = 0; i < c.size(); i++) post[i] = c[i];
| ~~^~~~~~~~~~
stations.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i = 1; i < c.size(); i++){
| ~~^~~~~~~~~~
stations.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i = 0; i < 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... |