#include "stations.h"
#include <vector>
#include <iostream>
#define int32_t int
#define int64_t long long
const int32_t MAX_N = 1000;
struct Vertex {
int32_t inTime, outTime, dep;
std::vector< int32_t > v;
};
Vertex g[MAX_N + 5];
void dfs(int32_t u, int32_t &t, int32_t par, int32_t dep) {
g[u].inTime = t++;
g[u].dep = dep;
for(auto &v : g[u].v) {
if(v != par) {
dfs(v, t, u, dep + 1);
}
}
g[u].outTime = t++;
}
std::vector< int32_t > label(int32_t n, int32_t k, std::vector< int32_t > u, std::vector< int32_t > v) {
for(int32_t i = 0; i < n; i++) {
g[i].v.clear();
}
for(int32_t i = 0; i < n - 1; i++) {
g[u[i]].v.push_back(v[i]);
g[v[i]].v.push_back(u[i]);
}
int32_t t = 0;
dfs(0, t, -1, 0);
std::vector< int32_t > labels(n);
for(int32_t i = 0; i < n; i++) {
if(g[i].dep % 2 == 0) {
labels[i] = g[i].inTime;
}
else {
labels[i] = g[i].outTime;
}
std::cout << labels[i] << " ";
}
std::cout << '\n';
return labels;
}
int32_t find_next_station(int32_t s, int32_t t, std::vector< int32_t > c) {
if(s < c[0]) {
if(t > c[c.size() - 2]) {
return c[c.size() - 1];
}
else {
for(int32_t i = 0; i < c.size() - 1; i++) {
if(t > c[i] && t <= c[i + 1]) {
return c[i + 1];
}
}
return c[0];
}
}
else {
if(t < c[0]) {
return c[0];
}
else if(t >= c[0] && t > s) {
return c[0];
}
else {
for(int32_t i = 1; i < c.size() - 1; i++) {
if(t >= c[i] && t < c[i + 1]) {
return c[i];
}
}
return c[c.size() - 1];
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:65:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int32_t i = 0; i < c.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~
stations.cpp:82:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int32_t i = 1; i < c.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Invalid length of array as the response of 'label'. scenario=0, n=10, len=0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Invalid length of array as the response of 'label'. scenario=0, n=996, len=0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Invalid length of array as the response of 'label'. scenario=0, n=2, len=0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Invalid length of array as the response of 'label'. scenario=0, n=2, len=0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Invalid length of array as the response of 'label'. scenario=0, n=3, len=0 |
2 |
Halted |
0 ms |
0 KB |
- |