#include "bits/stdc++.h"
#include "stations.h"
using namespace std;
#define MAX_N 1003
int lbl[MAX_N] ,nn = 0;
vector <vector<int>> adj;
void dfs(int u ,int p=-1 ,int t=0){
if(t == 0) lbl[u] = nn++;
for(int&v : adj[u]) if(v != p)
dfs(v ,u ,1-t);
if(t == 1) lbl[u] = nn++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
adj.clear() ,adj.resize(n);
for(int i = 0; i < u.size(); i++)
adj[u[i]].push_back(v[i]),
adj[v[i]].push_back(u[i]);
nn = 0 ,dfs(0);
return {lbl ,lbl+n};
}
int find_next_station(int s, int t, vector<int> c) {
if(count(c.begin() ,c.end() ,t))
return t;
if(s < c.front()){
if(t < s)
return c.back();
for(int&i : c) if(t <= i)
return i;
return c.back();
}else{
if(t > s)
return c.front();
reverse(c.begin() ,c.end());
for(int&i : c) if(i <= t)
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:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i = 0; i < u.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
544 ms |
680 KB |
Output is correct |
2 |
Correct |
501 ms |
656 KB |
Output is correct |
3 |
Correct |
1202 ms |
476 KB |
Output is correct |
4 |
Correct |
814 ms |
532 KB |
Output is correct |
5 |
Correct |
658 ms |
404 KB |
Output is correct |
6 |
Correct |
459 ms |
620 KB |
Output is correct |
7 |
Correct |
585 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
472 KB |
Output is correct |
9 |
Correct |
5 ms |
472 KB |
Output is correct |
10 |
Correct |
2 ms |
472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
500 ms |
496 KB |
Output is correct |
2 |
Correct |
636 ms |
528 KB |
Output is correct |
3 |
Correct |
1077 ms |
400 KB |
Output is correct |
4 |
Correct |
843 ms |
528 KB |
Output is correct |
5 |
Correct |
792 ms |
404 KB |
Output is correct |
6 |
Correct |
599 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
566 ms |
656 KB |
Output is correct |
2 |
Correct |
592 ms |
692 KB |
Output is correct |
3 |
Correct |
1202 ms |
404 KB |
Output is correct |
4 |
Correct |
792 ms |
428 KB |
Output is correct |
5 |
Correct |
577 ms |
528 KB |
Output is correct |
6 |
Correct |
453 ms |
744 KB |
Output is correct |
7 |
Correct |
620 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
472 KB |
Output is correct |
9 |
Correct |
6 ms |
480 KB |
Output is correct |
10 |
Correct |
2 ms |
472 KB |
Output is correct |
11 |
Correct |
691 ms |
488 KB |
Output is correct |
12 |
Correct |
578 ms |
528 KB |
Output is correct |
13 |
Correct |
597 ms |
608 KB |
Output is correct |
14 |
Correct |
557 ms |
528 KB |
Output is correct |
15 |
Correct |
52 ms |
400 KB |
Output is correct |
16 |
Correct |
66 ms |
528 KB |
Output is correct |
17 |
Correct |
148 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1075 ms |
468 KB |
Output is correct |
2 |
Correct |
870 ms |
400 KB |
Output is correct |
3 |
Correct |
793 ms |
400 KB |
Output is correct |
4 |
Correct |
3 ms |
480 KB |
Output is correct |
5 |
Correct |
6 ms |
456 KB |
Output is correct |
6 |
Correct |
2 ms |
472 KB |
Output is correct |
7 |
Correct |
755 ms |
400 KB |
Output is correct |
8 |
Correct |
1251 ms |
520 KB |
Output is correct |
9 |
Correct |
886 ms |
488 KB |
Output is correct |
10 |
Correct |
585 ms |
496 KB |
Output is correct |
11 |
Correct |
5 ms |
472 KB |
Output is correct |
12 |
Correct |
6 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
480 KB |
Output is correct |
14 |
Correct |
5 ms |
480 KB |
Output is correct |
15 |
Correct |
2 ms |
472 KB |
Output is correct |
16 |
Correct |
573 ms |
400 KB |
Output is correct |
17 |
Correct |
742 ms |
528 KB |
Output is correct |
18 |
Correct |
643 ms |
488 KB |
Output is correct |
19 |
Correct |
670 ms |
488 KB |
Output is correct |
20 |
Correct |
716 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
631 ms |
620 KB |
Output is correct |
2 |
Correct |
533 ms |
604 KB |
Output is correct |
3 |
Correct |
1029 ms |
468 KB |
Output is correct |
4 |
Correct |
813 ms |
492 KB |
Output is correct |
5 |
Correct |
725 ms |
492 KB |
Output is correct |
6 |
Correct |
629 ms |
620 KB |
Output is correct |
7 |
Correct |
481 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
472 KB |
Output is correct |
9 |
Correct |
4 ms |
484 KB |
Output is correct |
10 |
Correct |
2 ms |
472 KB |
Output is correct |
11 |
Correct |
609 ms |
484 KB |
Output is correct |
12 |
Correct |
601 ms |
496 KB |
Output is correct |
13 |
Correct |
1113 ms |
400 KB |
Output is correct |
14 |
Correct |
754 ms |
492 KB |
Output is correct |
15 |
Correct |
610 ms |
492 KB |
Output is correct |
16 |
Correct |
506 ms |
492 KB |
Output is correct |
17 |
Correct |
836 ms |
400 KB |
Output is correct |
18 |
Correct |
533 ms |
576 KB |
Output is correct |
19 |
Correct |
578 ms |
620 KB |
Output is correct |
20 |
Correct |
618 ms |
520 KB |
Output is correct |
21 |
Correct |
58 ms |
452 KB |
Output is correct |
22 |
Correct |
86 ms |
548 KB |
Output is correct |
23 |
Correct |
128 ms |
528 KB |
Output is correct |
24 |
Correct |
4 ms |
472 KB |
Output is correct |
25 |
Correct |
7 ms |
472 KB |
Output is correct |
26 |
Correct |
6 ms |
472 KB |
Output is correct |
27 |
Correct |
4 ms |
472 KB |
Output is correct |
28 |
Correct |
2 ms |
472 KB |
Output is correct |
29 |
Correct |
711 ms |
400 KB |
Output is correct |
30 |
Correct |
513 ms |
500 KB |
Output is correct |
31 |
Correct |
643 ms |
404 KB |
Output is correct |
32 |
Correct |
644 ms |
400 KB |
Output is correct |
33 |
Correct |
619 ms |
624 KB |
Output is correct |
34 |
Correct |
294 ms |
660 KB |
Output is correct |
35 |
Correct |
507 ms |
648 KB |
Output is correct |
36 |
Correct |
524 ms |
736 KB |
Output is correct |
37 |
Correct |
576 ms |
620 KB |
Output is correct |
38 |
Correct |
597 ms |
608 KB |
Output is correct |
39 |
Correct |
552 ms |
624 KB |
Output is correct |
40 |
Correct |
508 ms |
524 KB |
Output is correct |
41 |
Correct |
459 ms |
736 KB |
Output is correct |
42 |
Correct |
74 ms |
628 KB |
Output is correct |
43 |
Correct |
110 ms |
528 KB |
Output is correct |
44 |
Correct |
184 ms |
588 KB |
Output is correct |
45 |
Correct |
214 ms |
528 KB |
Output is correct |
46 |
Correct |
431 ms |
536 KB |
Output is correct |
47 |
Correct |
352 ms |
528 KB |
Output is correct |
48 |
Correct |
73 ms |
512 KB |
Output is correct |
49 |
Correct |
78 ms |
624 KB |
Output is correct |