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 <algorithm>
#include <iostream>
using namespace std;
void dfs(int cur, int ant, int & dtime, int h, vector<int> &labels, vector<vector<int> > & adj) {
if (h%2==0)
labels[cur]=dtime++;
for (int ni: adj[cur]) {
if (ni==ant)continue;
dfs(ni, cur, dtime, h+1, labels, adj);
}
if (h%2==1) {
labels[cur]=dtime++;
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
for (int i = 0; i < n; i++) {
labels[i] = i;
}
int d =0;
vector<vector<int> > adj(n);
for (int i =0; i < u.size(); i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0,0, d, 0, labels, adj);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(c.begin(), c.end());
//cout << "("<<s<<","<<t<<")";
for (int i =0; i < c.size(); i++) {
if (c[i]==t)return t;
}
if (s==0) {
int prev=0;
for (int i=0; i < c.size(); i++) {
if (prev <= t && t <= c[i])
return c[i];
prev=c[i];
}
return -1;
}
if (c[0] < s) {
if (t < c[0] || t > s)return c[0];
int prev=s;
for (int i = c.size()-1; i >=0; i--){
if (c[i] <= t && t <= prev) return c[i];
prev=c[i];
}
return -2;
} else {
if(t<s||t>c[c.size()-1]) return c[c.size()-1];
int prev=s;
for (int i = 0; i < c.size(); i++) {
if (prev<= t && t <= c[i])return c[i];
prev=c[i];
}
return -3;
}
}
Compilation message (stderr)
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i =0; i < u.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i =0; i < c.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp:45:25: 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(); i++) {
| ~~^~~~~~~~~~
stations.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | 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... |