#include "stations.h"
#include <cstdio>
#include <cassert>
#include <map>
#include <vector>
#include <algorithm>
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v);
int find_next_station(int s, int t, std::vector<int> c);
std::vector<int> adj[1024];
int ans[1024];
int sz[1024];
void dfs(int node, int prv, int l, int r, int dep) {
if(dep & 1) {
ans[node] = r;
r--;
}
else {
ans[node] = l;
l++;
}
for(int x: adj[node]) {
if(x != prv) {
dfs(x, node, l, l + sz[x] - 1, dep + 1);
l += sz[x];
}
}
}
void fuck(int node, int prv) {
sz[node] = 1;
for(int x: adj[node]) {
if(x != prv) {
fuck(x, node);
sz[node] += sz[x];
}
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
for(int i=0; i<n; i++) {
adj[i].clear();
}
for(int i=0; i<n-1; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
fuck(0, -1);
dfs(0, -1, 0, n-1, 0);
for(int i=0; i<n; i++) labels[i] = ans[i];
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c[0] > s) { // Current node is an even depth node
for(int i=0; i<c.size() - 1; i++) {
if(s < t && t <= c[i]) return c[i];
s = c[i];
}
return c[c.size() - 1];
}
else { // Current node is an odd depth node
for(int i=c.size()-1; i>0; i--) {
if(c[i] <= t && t < s) return c[i];
s = c[i];
}
return c[0];
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i=0; i<c.size() - 1; i++) {
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
437 ms |
648 KB |
Output is correct |
2 |
Correct |
399 ms |
684 KB |
Output is correct |
3 |
Correct |
684 ms |
416 KB |
Output is correct |
4 |
Correct |
515 ms |
524 KB |
Output is correct |
5 |
Correct |
488 ms |
420 KB |
Output is correct |
6 |
Correct |
415 ms |
544 KB |
Output is correct |
7 |
Correct |
349 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
500 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
410 ms |
512 KB |
Output is correct |
2 |
Correct |
453 ms |
512 KB |
Output is correct |
3 |
Correct |
744 ms |
420 KB |
Output is correct |
4 |
Correct |
544 ms |
420 KB |
Output is correct |
5 |
Correct |
499 ms |
524 KB |
Output is correct |
6 |
Correct |
364 ms |
548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
475 ms |
544 KB |
Output is correct |
2 |
Correct |
390 ms |
656 KB |
Output is correct |
3 |
Correct |
693 ms |
416 KB |
Output is correct |
4 |
Correct |
534 ms |
432 KB |
Output is correct |
5 |
Correct |
449 ms |
528 KB |
Output is correct |
6 |
Correct |
355 ms |
548 KB |
Output is correct |
7 |
Correct |
357 ms |
516 KB |
Output is correct |
8 |
Correct |
2 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
500 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
501 ms |
436 KB |
Output is correct |
12 |
Correct |
411 ms |
756 KB |
Output is correct |
13 |
Correct |
397 ms |
548 KB |
Output is correct |
14 |
Correct |
344 ms |
548 KB |
Output is correct |
15 |
Correct |
38 ms |
456 KB |
Output is correct |
16 |
Correct |
53 ms |
612 KB |
Output is correct |
17 |
Correct |
83 ms |
688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
772 ms |
420 KB |
Output is correct |
2 |
Correct |
545 ms |
420 KB |
Output is correct |
3 |
Correct |
504 ms |
416 KB |
Output is correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
5 |
Correct |
3 ms |
500 KB |
Output is correct |
6 |
Correct |
0 ms |
500 KB |
Output is correct |
7 |
Correct |
496 ms |
524 KB |
Output is correct |
8 |
Correct |
806 ms |
516 KB |
Output is correct |
9 |
Correct |
620 ms |
516 KB |
Output is correct |
10 |
Correct |
472 ms |
416 KB |
Output is correct |
11 |
Correct |
4 ms |
492 KB |
Output is correct |
12 |
Correct |
4 ms |
500 KB |
Output is correct |
13 |
Correct |
4 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
500 KB |
Output is correct |
16 |
Correct |
452 ms |
416 KB |
Output is correct |
17 |
Correct |
409 ms |
416 KB |
Output is correct |
18 |
Correct |
464 ms |
520 KB |
Output is correct |
19 |
Correct |
448 ms |
420 KB |
Output is correct |
20 |
Correct |
408 ms |
420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
440 ms |
644 KB |
Output is correct |
2 |
Correct |
367 ms |
544 KB |
Output is correct |
3 |
Correct |
737 ms |
420 KB |
Output is correct |
4 |
Correct |
496 ms |
520 KB |
Output is correct |
5 |
Correct |
486 ms |
420 KB |
Output is correct |
6 |
Correct |
386 ms |
548 KB |
Output is correct |
7 |
Correct |
368 ms |
520 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
500 KB |
Output is correct |
11 |
Correct |
368 ms |
508 KB |
Output is correct |
12 |
Correct |
471 ms |
544 KB |
Output is correct |
13 |
Correct |
780 ms |
524 KB |
Output is correct |
14 |
Correct |
553 ms |
420 KB |
Output is correct |
15 |
Correct |
504 ms |
416 KB |
Output is correct |
16 |
Correct |
387 ms |
544 KB |
Output is correct |
17 |
Correct |
473 ms |
644 KB |
Output is correct |
18 |
Correct |
360 ms |
656 KB |
Output is correct |
19 |
Correct |
411 ms |
792 KB |
Output is correct |
20 |
Correct |
377 ms |
536 KB |
Output is correct |
21 |
Correct |
48 ms |
472 KB |
Output is correct |
22 |
Correct |
62 ms |
552 KB |
Output is correct |
23 |
Correct |
93 ms |
544 KB |
Output is correct |
24 |
Correct |
3 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
500 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
488 KB |
Output is correct |
29 |
Correct |
415 ms |
420 KB |
Output is correct |
30 |
Correct |
464 ms |
520 KB |
Output is correct |
31 |
Correct |
443 ms |
420 KB |
Output is correct |
32 |
Correct |
395 ms |
520 KB |
Output is correct |
33 |
Correct |
391 ms |
420 KB |
Output is correct |
34 |
Correct |
265 ms |
544 KB |
Output is correct |
35 |
Correct |
345 ms |
760 KB |
Output is correct |
36 |
Correct |
362 ms |
744 KB |
Output is correct |
37 |
Correct |
400 ms |
704 KB |
Output is correct |
38 |
Correct |
378 ms |
604 KB |
Output is correct |
39 |
Correct |
407 ms |
516 KB |
Output is correct |
40 |
Correct |
394 ms |
544 KB |
Output is correct |
41 |
Correct |
416 ms |
652 KB |
Output is correct |
42 |
Correct |
57 ms |
600 KB |
Output is correct |
43 |
Correct |
73 ms |
544 KB |
Output is correct |
44 |
Correct |
114 ms |
524 KB |
Output is correct |
45 |
Correct |
114 ms |
524 KB |
Output is correct |
46 |
Correct |
213 ms |
548 KB |
Output is correct |
47 |
Correct |
230 ms |
520 KB |
Output is correct |
48 |
Correct |
57 ms |
576 KB |
Output is correct |
49 |
Correct |
58 ms |
744 KB |
Output is correct |