#include "stations.h"
#include <bits/stdc++.h>
#include <vector>
int timer = 0;
using namespace std;
vector < vector <int> > Adj;
vector <int> tin,tout,depth;
void PREP(int n) {
Adj.clear();
tin.clear();
tout.clear();
depth.clear();
Adj.resize(n);
tin.resize(n);
tout.resize(n);
depth.resize(n);
depth[1] = 0;
timer = 1;
}
void DFS(int v,int p) {
tin[v] = timer;
timer++;
for (int x : Adj[v]) {
if (x == p) continue;
DFS(x,v);
depth[x] = depth[v] + 1;
}
tout[v] = timer;
timer++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
vector <int> labels(n);
vector < pair <int,int> > LBLS;
PREP(n);
for (int i = 0;i < n-1;i++) {
int a = u[i];
int b = v[i];
Adj[a].push_back(b);
Adj[b].push_back(a);
}
DFS(1,-1);
for (int i = 0;i < n;i++) {
if (depth[i] % 2 == 0) {
LBLS.push_back(make_pair(tin[i],i));
} else {
LBLS.push_back(make_pair(tout[i],i));
}
}
sort(LBLS.begin(),LBLS.end());
for (int i = 0;i < n;i++) {
labels[LBLS[i].second] = i;
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if (c.back() < s) {
c.push_back(s);
sort(c.begin(),c.end());
for (int i = 1;i < c.size()-1;i++) {
if (c[i] <= t && c[i+1] > t) {
return c[i];
}
}
return c[0];
} else {
c.push_back(s);
sort(c.begin(),c.end());
for (int i = 0;i < c.size()-1;i++) {
if (c[i] >= t && c[i+1] < t) {
return c[i];
}
}
return c.back();
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:64:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for (int i = 1;i < c.size()-1;i++) {
| ~~^~~~~~~~~~~~
stations.cpp:73:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i = 0;i < c.size()-1;i++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
542 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
579 ms |
792 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
741 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1015 ms |
640 KB |
Output is correct |
2 |
Incorrect |
878 ms |
644 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
492 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |