#include "stations.h"
#include <stdlib.h>
#include <vector>
using namespace std;
typedef vector<int> vi;
const int N = 1000;
int *ej[N], eo[N];
void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
int ta[N], tb[N];
void dfs(int p, int i) {
static int time;
int o;
ta[i] = time++;
for (o = eo[i]; o--; ) {
int j = ej[i][o];
if (j != p)
dfs(i, j);
}
tb[i] = time - 1;
}
vi label(int n, int k, vi uu, vi vv) {
int h, i;
vi labels(n);
for (i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
for (h = 0; h < n - 1; h++)
append(uu[h], vv[h]), append(vv[h], uu[h]);
dfs(-1, 0);
for (i = 0; i < n; i++)
labels[i] = ta[i] * N + tb[i];
return labels;
}
int find_next_station(int s, int t, vi cc) {
int m = cc.size(), h;
for (h = 0; h < m; h++)
if (cc[h] / N <= t && t <= cc[h] % N)
return cc[h];
return -1;
}
Compilation message
stations.cpp: In function 'void append(int, int)':
stations.cpp:15:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
15 | if (o >= 2 && (o & o - 1) == 0)
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1153 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1158 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
584 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
292 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3123 ms |
1514856 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |