#include <bits/stdc++.h>
using namespace std;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
vector<int> labels(n);
vector<vector<int>> adj(n);
for(int i=0;i<n-1;i++){
adj[u[i]].emplace_back(v[i]);
adj[v[i]].emplace_back(u[i]);
}
int tim = 0;
function<void(int,int,bool)> dfs = [&](int x,int p,bool type){
if(type)labels[x]=tim++;
for(int&i:adj[x])if(i!=p)dfs(i,x,!type);
if(!type)labels[x]=tim++;
};
dfs(0,-1,true);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s<c.front()){
// this is a min order
c.insert(c.begin(),s);
for(int i=1;i<c.size();i++){
if(c[i-1]<t and t<=c[i])return c[i];
}
return c.back();
} else {
// this is a max order
c.insert(c.end(),s);
for(int i=0;i<c.size()-1;i++){
if(c[i]<=t and t<c[i+1])return c[i];
}
return c.front();
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:25:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i=1;i<c.size();i++){
| ~^~~~~~~~~
stations.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i=0;i<c.size()-1;i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
940 KB |
Output is correct |
2 |
Correct |
240 ms |
940 KB |
Output is correct |
3 |
Correct |
522 ms |
684 KB |
Output is correct |
4 |
Correct |
420 ms |
684 KB |
Output is correct |
5 |
Correct |
391 ms |
684 KB |
Output is correct |
6 |
Correct |
286 ms |
940 KB |
Output is correct |
7 |
Correct |
282 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
764 KB |
Output is correct |
9 |
Correct |
2 ms |
760 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
684 KB |
Output is correct |
2 |
Correct |
360 ms |
684 KB |
Output is correct |
3 |
Correct |
534 ms |
684 KB |
Output is correct |
4 |
Correct |
399 ms |
936 KB |
Output is correct |
5 |
Correct |
361 ms |
684 KB |
Output is correct |
6 |
Correct |
287 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
354 ms |
944 KB |
Output is correct |
2 |
Correct |
289 ms |
940 KB |
Output is correct |
3 |
Correct |
592 ms |
688 KB |
Output is correct |
4 |
Correct |
422 ms |
684 KB |
Output is correct |
5 |
Correct |
399 ms |
684 KB |
Output is correct |
6 |
Correct |
264 ms |
944 KB |
Output is correct |
7 |
Correct |
309 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
415 ms |
684 KB |
Output is correct |
12 |
Correct |
289 ms |
1020 KB |
Output is correct |
13 |
Correct |
294 ms |
1272 KB |
Output is correct |
14 |
Correct |
292 ms |
684 KB |
Output is correct |
15 |
Correct |
44 ms |
768 KB |
Output is correct |
16 |
Correct |
40 ms |
684 KB |
Output is correct |
17 |
Correct |
81 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
629 ms |
684 KB |
Output is correct |
2 |
Correct |
457 ms |
684 KB |
Output is correct |
3 |
Correct |
403 ms |
688 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 |
768 KB |
Output is correct |
7 |
Correct |
377 ms |
772 KB |
Output is correct |
8 |
Correct |
607 ms |
684 KB |
Output is correct |
9 |
Correct |
499 ms |
684 KB |
Output is correct |
10 |
Correct |
379 ms |
684 KB |
Output is correct |
11 |
Correct |
2 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
768 KB |
Output is correct |
13 |
Correct |
2 ms |
772 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
0 ms |
768 KB |
Output is correct |
16 |
Correct |
314 ms |
688 KB |
Output is correct |
17 |
Correct |
342 ms |
684 KB |
Output is correct |
18 |
Correct |
334 ms |
684 KB |
Output is correct |
19 |
Correct |
331 ms |
684 KB |
Output is correct |
20 |
Correct |
312 ms |
712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
402 ms |
940 KB |
Output is correct |
2 |
Correct |
284 ms |
940 KB |
Output is correct |
3 |
Correct |
579 ms |
684 KB |
Output is correct |
4 |
Correct |
467 ms |
684 KB |
Output is correct |
5 |
Correct |
391 ms |
684 KB |
Output is correct |
6 |
Correct |
291 ms |
940 KB |
Output is correct |
7 |
Correct |
295 ms |
688 KB |
Output is correct |
8 |
Correct |
1 ms |
764 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
293 ms |
684 KB |
Output is correct |
12 |
Correct |
359 ms |
688 KB |
Output is correct |
13 |
Correct |
599 ms |
684 KB |
Output is correct |
14 |
Correct |
475 ms |
684 KB |
Output is correct |
15 |
Correct |
387 ms |
684 KB |
Output is correct |
16 |
Correct |
325 ms |
684 KB |
Output is correct |
17 |
Correct |
392 ms |
684 KB |
Output is correct |
18 |
Correct |
343 ms |
932 KB |
Output is correct |
19 |
Correct |
324 ms |
1020 KB |
Output is correct |
20 |
Correct |
325 ms |
684 KB |
Output is correct |
21 |
Correct |
30 ms |
768 KB |
Output is correct |
22 |
Correct |
36 ms |
764 KB |
Output is correct |
23 |
Correct |
57 ms |
768 KB |
Output is correct |
24 |
Correct |
2 ms |
776 KB |
Output is correct |
25 |
Correct |
2 ms |
768 KB |
Output is correct |
26 |
Correct |
3 ms |
776 KB |
Output is correct |
27 |
Correct |
1 ms |
768 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
327 ms |
684 KB |
Output is correct |
30 |
Correct |
360 ms |
684 KB |
Output is correct |
31 |
Correct |
343 ms |
684 KB |
Output is correct |
32 |
Correct |
358 ms |
684 KB |
Output is correct |
33 |
Correct |
344 ms |
684 KB |
Output is correct |
34 |
Correct |
204 ms |
940 KB |
Output is correct |
35 |
Correct |
296 ms |
1032 KB |
Output is correct |
36 |
Correct |
304 ms |
1040 KB |
Output is correct |
37 |
Correct |
313 ms |
1020 KB |
Output is correct |
38 |
Correct |
339 ms |
1184 KB |
Output is correct |
39 |
Correct |
329 ms |
780 KB |
Output is correct |
40 |
Correct |
303 ms |
772 KB |
Output is correct |
41 |
Correct |
320 ms |
1016 KB |
Output is correct |
42 |
Correct |
42 ms |
760 KB |
Output is correct |
43 |
Correct |
56 ms |
684 KB |
Output is correct |
44 |
Correct |
83 ms |
792 KB |
Output is correct |
45 |
Correct |
118 ms |
684 KB |
Output is correct |
46 |
Correct |
191 ms |
684 KB |
Output is correct |
47 |
Correct |
192 ms |
684 KB |
Output is correct |
48 |
Correct |
36 ms |
684 KB |
Output is correct |
49 |
Correct |
30 ms |
984 KB |
Output is correct |