#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[10000];
int lbl[10000], cnt;
void dfs(int i, int p, int d) {
if(d % 2 == 0)
lbl[i] = cnt++;
for(int a: adj[i]) {
if(a == p) continue;
dfs(a, i, d+1);
}
if(d % 2 == 1)
lbl[i] = cnt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n);
for(int i=0; i<u.size(); i++) {
//printf("edge = %d, %d\n", u[i], v[i]);
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, -1, 0);
for(int i=0; i<n; i++) {
//printf("label %d = %d\n", i, lbl[i]);
labels[i] = lbl[i];
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if(c[0] < s) { // s is out
reverse(c.begin(), c.end());
}
c.insert(c.begin(), s);
for(int i=1; i<c.size(); i++) {
//printf("compare between %d, %d\n", c[i-1], c[i]);
if((c[i-1] <= t && t <= c[i]) || (c[i] <= t && t <= c[i-1])) {
return c[i];
}
}
return c.back();
}
// int main() {
// int s, t, w;
// cin >> s >> t >> w;
// vector<int> c(w);
// for(int i=0; i<w; i++) {
// cin >> c[i];
// }
// cout << find_next_station(s, t, c);
// }
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i=0; i<u.size(); i++) {
| ~^~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:36:16: 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=1; i<c.size(); i++) {
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1460 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3039 ms |
720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1531 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
873 ms |
1152 KB |
Output is correct |
2 |
Runtime error |
1267 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2448 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |