#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> adj[1005];
int timer = 0, st[1005], en[1005], l[1005];
void dfs(int i, int p, int d) {
st[i] = timer;
timer++;
if (d % 2 == 0) {
l[i] = st[i];
}
for (int j : adj[i]) {
if (j == p) {
continue;
}
dfs(j, i, d+1);
}
en[i] = timer;
timer++;
if (d % 2 == 1) {
l[i] = en[i];
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n);
timer = 0;
for (int i = 0; i <= n; i++) {
adj[i].clear();
en[i] = 0;
}
int leaf = 0;
for (int i = 0; i < n-1; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
for (int i = 0; i < n; i++) {
sort(adj[i].begin(), adj[i].end());
if (adj[i].size() == 1) {
leaf = i;
}
}
dfs(leaf, -1, 0);
for (int i = 0; i < n; i++) {
labels[i] = l[i];
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
int ins = -1, outs = -1;
if (c.size() == 1) {
return c.back();
}
if (s == t) {
return s;
}
for (int i : c) {
if (i == t) {
return t;
}
}
if (s == 0) {
vector<int> in(c.size()), out(c.size());
ins = s;
outs = c.back()+1;
for (int i = 0; i < c.size(); i++) {
out[i] = c[i];
if (i == 0) {
in[i] = ins+1;
} else {
in[i] = out[i-1]+1;
}
}
for (int i = 0; i < c.size(); i++) {
if (in[i] < t && t < out[i]) {
return c[i];
}
}
return c.back();
} else {
int inp = -1, outp = -1;
vector<int> in(c.size()-1), out(c.size()-1);
if (s < c.front()) {
inp = s-1;
outp = c.back();
c.pop_back();
ins = s;
outs = c.back()+1;
for (int i = 0; i < c.size(); i++) {
out[i] = c[i];
if (i == 0) {
in[i] = ins+1;
} else {
in[i] = out[i-1]+1;
}
}
for (int i = 0; i < c.size(); i++) {
if (in[i] < t && t < out[i]) {
return c[i];
}
}
return outp;
} else {
inp = c.front();
outp = s+1;
c.erase(c.begin());
ins = c.front()-1;
outs = s;
for (int i = c.size()-1; i >= 0; i--) {
in[i] = c[i];
if (i == c.size()-1) {
out[i] = outs-1;
} else {
out[i] = in[i+1]-1;
}
}
for (int i = 0; i < c.size(); i++) {
if (in[i] < t && t < out[i]) {
return c[i];
}
}
return inp;
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:65:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i = 0; i < c.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp:73:27: 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(); i++) {
| ~~^~~~~~~~~~
stations.cpp:88:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for (int i = 0; i < c.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp:96:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for (int i = 0; i < c.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp:110:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | if (i == c.size()-1) {
| ~~^~~~~~~~~~~~~
stations.cpp:116:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
116 | for (int i = 0; i < c.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
600 KB |
Invalid labels (values out of range). scenario=2, k=1000, vertex=0, label=1216 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1032 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
361 ms |
940 KB |
Output is correct |
2 |
Correct |
337 ms |
936 KB |
Output is correct |
3 |
Correct |
576 ms |
684 KB |
Output is correct |
4 |
Correct |
439 ms |
684 KB |
Output is correct |
5 |
Correct |
393 ms |
684 KB |
Output is correct |
6 |
Correct |
290 ms |
936 KB |
Output is correct |
7 |
Correct |
306 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
776 KB |
Output is correct |
9 |
Correct |
1 ms |
776 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
389 ms |
684 KB |
Output is correct |
12 |
Correct |
334 ms |
1304 KB |
Output is correct |
13 |
Correct |
353 ms |
1040 KB |
Output is correct |
14 |
Correct |
318 ms |
700 KB |
Output is correct |
15 |
Correct |
26 ms |
784 KB |
Output is correct |
16 |
Correct |
30 ms |
764 KB |
Output is correct |
17 |
Correct |
59 ms |
960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
569 ms |
684 KB |
Output is correct |
2 |
Correct |
468 ms |
684 KB |
Output is correct |
3 |
Correct |
406 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
776 KB |
Output is correct |
6 |
Correct |
0 ms |
760 KB |
Output is correct |
7 |
Correct |
393 ms |
684 KB |
Output is correct |
8 |
Correct |
600 ms |
684 KB |
Output is correct |
9 |
Correct |
457 ms |
684 KB |
Output is correct |
10 |
Correct |
374 ms |
684 KB |
Output is correct |
11 |
Correct |
3 ms |
772 KB |
Output is correct |
12 |
Correct |
3 ms |
768 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
1 ms |
776 KB |
Output is correct |
16 |
Correct |
328 ms |
684 KB |
Output is correct |
17 |
Correct |
369 ms |
684 KB |
Output is correct |
18 |
Correct |
357 ms |
684 KB |
Output is correct |
19 |
Correct |
334 ms |
684 KB |
Output is correct |
20 |
Correct |
340 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
348 ms |
940 KB |
Partially correct |
2 |
Partially correct |
321 ms |
940 KB |
Partially correct |
3 |
Correct |
628 ms |
684 KB |
Output is correct |
4 |
Correct |
430 ms |
684 KB |
Output is correct |
5 |
Correct |
421 ms |
688 KB |
Output is correct |
6 |
Partially correct |
305 ms |
944 KB |
Partially correct |
7 |
Partially correct |
319 ms |
940 KB |
Partially correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
776 KB |
Output is correct |
11 |
Partially correct |
309 ms |
684 KB |
Partially correct |
12 |
Partially correct |
359 ms |
684 KB |
Partially correct |
13 |
Correct |
595 ms |
684 KB |
Output is correct |
14 |
Correct |
452 ms |
684 KB |
Output is correct |
15 |
Correct |
419 ms |
684 KB |
Output is correct |
16 |
Partially correct |
290 ms |
704 KB |
Partially correct |
17 |
Correct |
367 ms |
684 KB |
Output is correct |
18 |
Partially correct |
339 ms |
1192 KB |
Partially correct |
19 |
Partially correct |
327 ms |
1184 KB |
Partially correct |
20 |
Partially correct |
276 ms |
684 KB |
Partially correct |
21 |
Correct |
27 ms |
764 KB |
Output is correct |
22 |
Partially correct |
40 ms |
772 KB |
Partially correct |
23 |
Partially correct |
55 ms |
764 KB |
Partially correct |
24 |
Correct |
3 ms |
776 KB |
Output is correct |
25 |
Correct |
2 ms |
768 KB |
Output is correct |
26 |
Correct |
2 ms |
768 KB |
Output is correct |
27 |
Correct |
1 ms |
768 KB |
Output is correct |
28 |
Correct |
0 ms |
768 KB |
Output is correct |
29 |
Correct |
317 ms |
728 KB |
Output is correct |
30 |
Correct |
359 ms |
684 KB |
Output is correct |
31 |
Correct |
347 ms |
700 KB |
Output is correct |
32 |
Correct |
323 ms |
700 KB |
Output is correct |
33 |
Correct |
328 ms |
688 KB |
Output is correct |
34 |
Partially correct |
216 ms |
932 KB |
Partially correct |
35 |
Partially correct |
317 ms |
1380 KB |
Partially correct |
36 |
Partially correct |
322 ms |
940 KB |
Partially correct |
37 |
Partially correct |
309 ms |
808 KB |
Partially correct |
38 |
Partially correct |
297 ms |
1188 KB |
Partially correct |
39 |
Partially correct |
286 ms |
800 KB |
Partially correct |
40 |
Partially correct |
298 ms |
808 KB |
Partially correct |
41 |
Partially correct |
299 ms |
1048 KB |
Partially correct |
42 |
Partially correct |
31 ms |
760 KB |
Partially correct |
43 |
Partially correct |
57 ms |
716 KB |
Partially correct |
44 |
Partially correct |
75 ms |
744 KB |
Partially correct |
45 |
Partially correct |
88 ms |
768 KB |
Partially correct |
46 |
Partially correct |
196 ms |
684 KB |
Partially correct |
47 |
Partially correct |
205 ms |
688 KB |
Partially correct |
48 |
Partially correct |
32 ms |
988 KB |
Partially correct |
49 |
Partially correct |
27 ms |
768 KB |
Partially correct |