#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
vector<int> adj[1010];
int in[1010], out[1010], cnt;
void dfs(int here, int par, bool flag, vector<int>& labels) {
in[here] = cnt++;
for(int there : adj[here]) {
if(there == par) continue;
dfs(there, here, !flag, labels);
}
out[here] = cnt++;
labels[here] = (flag ? in[here] : out[here]);
}
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();
cnt = 0;
for(int i = 0; i < u.size(); i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, 0, 0, labels);
priority_queue<pi> pq;
for(int i = 0; i < n; i++) pq.push(pi(labels[i], i));
for(int i = n-1; i >= 0; i--) {
labels[pq.top().second] = i;
pq.pop();
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s < c[0]) {
if(s < t && t <= c[0]) return c[0];
for(int i = 1; i < c.size(); i++) if(c[i-1] < t && t <= c[i]) return c[i];
return *c.rbegin();
}
for(int i = 2; i < c.size(); i++) if(c[i-1] <= t && t < c[i]) return c[i-1];
if(*c.rbegin() <= t && t < s) return *c.rbegin();
return c[0];
}
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = 0; i < u.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 1; i < c.size(); i++) if(c[i-1] < t && t <= c[i]) return c[i];
| ~~^~~~~~~~~~
stations.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i = 2; i < c.size(); i++) if(c[i-1] <= t && t < c[i]) return c[i-1];
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
533 ms |
652 KB |
Output is correct |
2 |
Correct |
422 ms |
672 KB |
Output is correct |
3 |
Correct |
934 ms |
420 KB |
Output is correct |
4 |
Correct |
700 ms |
420 KB |
Output is correct |
5 |
Correct |
608 ms |
416 KB |
Output is correct |
6 |
Correct |
402 ms |
672 KB |
Output is correct |
7 |
Correct |
377 ms |
548 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
370 ms |
532 KB |
Output is correct |
2 |
Correct |
501 ms |
544 KB |
Output is correct |
3 |
Correct |
800 ms |
520 KB |
Output is correct |
4 |
Correct |
625 ms |
536 KB |
Output is correct |
5 |
Correct |
467 ms |
544 KB |
Output is correct |
6 |
Correct |
438 ms |
532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
545 ms |
664 KB |
Output is correct |
2 |
Correct |
426 ms |
660 KB |
Output is correct |
3 |
Correct |
842 ms |
416 KB |
Output is correct |
4 |
Correct |
644 ms |
528 KB |
Output is correct |
5 |
Correct |
469 ms |
548 KB |
Output is correct |
6 |
Correct |
483 ms |
676 KB |
Output is correct |
7 |
Correct |
430 ms |
540 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
5 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
496 KB |
Output is correct |
11 |
Correct |
582 ms |
532 KB |
Output is correct |
12 |
Correct |
455 ms |
792 KB |
Output is correct |
13 |
Correct |
479 ms |
776 KB |
Output is correct |
14 |
Correct |
494 ms |
532 KB |
Output is correct |
15 |
Correct |
56 ms |
616 KB |
Output is correct |
16 |
Correct |
61 ms |
576 KB |
Output is correct |
17 |
Correct |
92 ms |
672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
769 ms |
516 KB |
Output is correct |
2 |
Correct |
694 ms |
536 KB |
Output is correct |
3 |
Correct |
620 ms |
532 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
537 ms |
416 KB |
Output is correct |
8 |
Correct |
926 ms |
540 KB |
Output is correct |
9 |
Correct |
612 ms |
548 KB |
Output is correct |
10 |
Correct |
578 ms |
416 KB |
Output is correct |
11 |
Correct |
5 ms |
492 KB |
Output is correct |
12 |
Correct |
6 ms |
500 KB |
Output is correct |
13 |
Correct |
2 ms |
492 KB |
Output is correct |
14 |
Correct |
4 ms |
628 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
540 ms |
532 KB |
Output is correct |
17 |
Correct |
517 ms |
536 KB |
Output is correct |
18 |
Correct |
497 ms |
532 KB |
Output is correct |
19 |
Correct |
522 ms |
556 KB |
Output is correct |
20 |
Correct |
452 ms |
536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
470 ms |
664 KB |
Output is correct |
2 |
Correct |
443 ms |
660 KB |
Output is correct |
3 |
Correct |
946 ms |
420 KB |
Output is correct |
4 |
Correct |
667 ms |
536 KB |
Output is correct |
5 |
Correct |
579 ms |
528 KB |
Output is correct |
6 |
Correct |
464 ms |
660 KB |
Output is correct |
7 |
Correct |
439 ms |
532 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
366 ms |
536 KB |
Output is correct |
12 |
Correct |
533 ms |
548 KB |
Output is correct |
13 |
Correct |
776 ms |
444 KB |
Output is correct |
14 |
Correct |
655 ms |
536 KB |
Output is correct |
15 |
Correct |
568 ms |
416 KB |
Output is correct |
16 |
Correct |
385 ms |
532 KB |
Output is correct |
17 |
Correct |
583 ms |
416 KB |
Output is correct |
18 |
Correct |
413 ms |
656 KB |
Output is correct |
19 |
Correct |
462 ms |
760 KB |
Output is correct |
20 |
Correct |
430 ms |
524 KB |
Output is correct |
21 |
Correct |
59 ms |
572 KB |
Output is correct |
22 |
Correct |
62 ms |
544 KB |
Output is correct |
23 |
Correct |
93 ms |
548 KB |
Output is correct |
24 |
Correct |
4 ms |
500 KB |
Output is correct |
25 |
Correct |
5 ms |
500 KB |
Output is correct |
26 |
Correct |
4 ms |
620 KB |
Output is correct |
27 |
Correct |
3 ms |
500 KB |
Output is correct |
28 |
Correct |
2 ms |
488 KB |
Output is correct |
29 |
Correct |
469 ms |
536 KB |
Output is correct |
30 |
Correct |
421 ms |
660 KB |
Output is correct |
31 |
Correct |
529 ms |
536 KB |
Output is correct |
32 |
Correct |
448 ms |
532 KB |
Output is correct |
33 |
Correct |
535 ms |
420 KB |
Output is correct |
34 |
Correct |
324 ms |
676 KB |
Output is correct |
35 |
Correct |
434 ms |
896 KB |
Output is correct |
36 |
Correct |
436 ms |
768 KB |
Output is correct |
37 |
Correct |
462 ms |
648 KB |
Output is correct |
38 |
Correct |
448 ms |
640 KB |
Output is correct |
39 |
Correct |
443 ms |
664 KB |
Output is correct |
40 |
Correct |
469 ms |
728 KB |
Output is correct |
41 |
Correct |
470 ms |
828 KB |
Output is correct |
42 |
Correct |
57 ms |
672 KB |
Output is correct |
43 |
Correct |
99 ms |
672 KB |
Output is correct |
44 |
Correct |
121 ms |
676 KB |
Output is correct |
45 |
Correct |
174 ms |
528 KB |
Output is correct |
46 |
Correct |
293 ms |
548 KB |
Output is correct |
47 |
Correct |
301 ms |
532 KB |
Output is correct |
48 |
Correct |
43 ms |
916 KB |
Output is correct |
49 |
Correct |
57 ms |
828 KB |
Output is correct |