#include "stations.h"
#include <vector>
#include <algorithm>
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());
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 >=1; i--){
if (c[i] <= t && t <= prev) return c[i];
prev=c[i];
}
return -1;
} else {
if(t<s||t>c[c.size()-1]) return c[c.size()-1];
int prev=s;
for (int i = 0; i < c.size()-1; i++) {
if (prev<= t && t <= c[i])return c[i];
prev=c[i];
}
return -1;
}
}
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int i =0; i < u.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i =0; i < c.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp:41:25: 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++) {
| ~~^~~~~~~~~~
stations.cpp:59:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 0; i < c.size()-1; i++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
578 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
471 ms |
768 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
557 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
887 ms |
640 KB |
Output is correct |
2 |
Incorrect |
736 ms |
640 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
629 ms |
1048 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |