#include "stations.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <map>
#include <cstdio>
using namespace std;
const int maxn = 1010;
vector<int> g[maxn];
vector<int> lab, siz;
int calc_siz(int x, int p) {
for (int i : g[x]) {
if (i == p)continue;
siz[x] += calc_siz(i, x);
}
return siz[x];
}
void calc_lab(int x, int p) {
int sum = 0, pl = (p < 0 ? maxn : lab[p]);
for (int i : g[x]) {
if (i == p)continue;
if (pl > lab[x]) {
lab[i] = lab[x] + siz[i] + sum;
}
else {
lab[i] = lab[x] - siz[i] - sum;
}
calc_lab(i, x);
sum += siz[i];
}
return;
}
vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
lab.assign(n, 0);
siz.assign(n, 1);
for (int i = 0; i < n; i++)g[i].clear();
for (int i = 0; i < u.size(); i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
calc_siz(0, -1);
calc_lab(0, -1);
return lab;
}
int find_next_station(int s, int t, std::vector<int> c) {
if (s > c[0]) {
reverse(c.begin(), c.end());
for (int i : c) {
if (s > t && t >= i)return i;
}
return c.back();
}
else {
for (int i : c) {
if (s < t && t <= i)return i;
}
return c.back();
}
}
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < u.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
626 ms |
544 KB |
Output is correct |
2 |
Correct |
591 ms |
728 KB |
Output is correct |
3 |
Correct |
934 ms |
528 KB |
Output is correct |
4 |
Correct |
678 ms |
528 KB |
Output is correct |
5 |
Correct |
580 ms |
532 KB |
Output is correct |
6 |
Correct |
321 ms |
652 KB |
Output is correct |
7 |
Correct |
515 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
496 KB |
Output is correct |
9 |
Correct |
5 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
486 ms |
580 KB |
Output is correct |
2 |
Correct |
663 ms |
524 KB |
Output is correct |
3 |
Correct |
652 ms |
420 KB |
Output is correct |
4 |
Correct |
981 ms |
416 KB |
Output is correct |
5 |
Correct |
686 ms |
416 KB |
Output is correct |
6 |
Correct |
627 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
648 ms |
660 KB |
Output is correct |
2 |
Correct |
524 ms |
676 KB |
Output is correct |
3 |
Correct |
957 ms |
524 KB |
Output is correct |
4 |
Correct |
716 ms |
416 KB |
Output is correct |
5 |
Correct |
661 ms |
528 KB |
Output is correct |
6 |
Correct |
449 ms |
648 KB |
Output is correct |
7 |
Correct |
513 ms |
528 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
660 ms |
420 KB |
Output is correct |
12 |
Correct |
581 ms |
840 KB |
Output is correct |
13 |
Correct |
496 ms |
892 KB |
Output is correct |
14 |
Correct |
350 ms |
524 KB |
Output is correct |
15 |
Correct |
35 ms |
544 KB |
Output is correct |
16 |
Correct |
62 ms |
724 KB |
Output is correct |
17 |
Correct |
93 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
824 ms |
416 KB |
Output is correct |
2 |
Correct |
576 ms |
524 KB |
Output is correct |
3 |
Correct |
524 ms |
420 KB |
Output is correct |
4 |
Correct |
2 ms |
568 KB |
Output is correct |
5 |
Correct |
5 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
504 ms |
524 KB |
Output is correct |
8 |
Correct |
999 ms |
528 KB |
Output is correct |
9 |
Correct |
1123 ms |
528 KB |
Output is correct |
10 |
Correct |
920 ms |
484 KB |
Output is correct |
11 |
Correct |
6 ms |
492 KB |
Output is correct |
12 |
Correct |
6 ms |
496 KB |
Output is correct |
13 |
Correct |
4 ms |
492 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
568 ms |
528 KB |
Output is correct |
17 |
Correct |
441 ms |
416 KB |
Output is correct |
18 |
Correct |
825 ms |
524 KB |
Output is correct |
19 |
Correct |
455 ms |
528 KB |
Output is correct |
20 |
Correct |
631 ms |
420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
908 ms |
656 KB |
Output is correct |
2 |
Correct |
446 ms |
544 KB |
Output is correct |
3 |
Correct |
911 ms |
532 KB |
Output is correct |
4 |
Correct |
710 ms |
528 KB |
Output is correct |
5 |
Correct |
520 ms |
416 KB |
Output is correct |
6 |
Correct |
455 ms |
672 KB |
Output is correct |
7 |
Correct |
506 ms |
548 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
425 ms |
548 KB |
Output is correct |
12 |
Correct |
527 ms |
528 KB |
Output is correct |
13 |
Correct |
858 ms |
420 KB |
Output is correct |
14 |
Correct |
593 ms |
528 KB |
Output is correct |
15 |
Correct |
489 ms |
528 KB |
Output is correct |
16 |
Correct |
539 ms |
544 KB |
Output is correct |
17 |
Correct |
622 ms |
532 KB |
Output is correct |
18 |
Correct |
452 ms |
632 KB |
Output is correct |
19 |
Correct |
454 ms |
648 KB |
Output is correct |
20 |
Correct |
474 ms |
528 KB |
Output is correct |
21 |
Correct |
50 ms |
492 KB |
Output is correct |
22 |
Correct |
71 ms |
600 KB |
Output is correct |
23 |
Correct |
95 ms |
548 KB |
Output is correct |
24 |
Correct |
6 ms |
500 KB |
Output is correct |
25 |
Correct |
5 ms |
492 KB |
Output is correct |
26 |
Correct |
4 ms |
500 KB |
Output is correct |
27 |
Correct |
4 ms |
500 KB |
Output is correct |
28 |
Correct |
2 ms |
500 KB |
Output is correct |
29 |
Correct |
467 ms |
416 KB |
Output is correct |
30 |
Correct |
461 ms |
416 KB |
Output is correct |
31 |
Correct |
466 ms |
524 KB |
Output is correct |
32 |
Correct |
466 ms |
420 KB |
Output is correct |
33 |
Correct |
454 ms |
420 KB |
Output is correct |
34 |
Correct |
298 ms |
540 KB |
Output is correct |
35 |
Correct |
431 ms |
652 KB |
Output is correct |
36 |
Correct |
453 ms |
744 KB |
Output is correct |
37 |
Correct |
372 ms |
520 KB |
Output is correct |
38 |
Correct |
395 ms |
760 KB |
Output is correct |
39 |
Correct |
444 ms |
668 KB |
Output is correct |
40 |
Correct |
463 ms |
668 KB |
Output is correct |
41 |
Correct |
439 ms |
652 KB |
Output is correct |
42 |
Correct |
52 ms |
572 KB |
Output is correct |
43 |
Correct |
87 ms |
572 KB |
Output is correct |
44 |
Correct |
125 ms |
548 KB |
Output is correct |
45 |
Correct |
169 ms |
612 KB |
Output is correct |
46 |
Correct |
287 ms |
532 KB |
Output is correct |
47 |
Correct |
271 ms |
544 KB |
Output is correct |
48 |
Correct |
62 ms |
752 KB |
Output is correct |
49 |
Correct |
65 ms |
784 KB |
Output is correct |