#include<bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
vector<int>Vis, new_;
vector<vector<int>>A;
bool even;
int time_;
void dfs(int ind){
Vis[ind]=1;
bool odd=!even;
if(!odd) new_[ind]=time_++;
for(int i=0;i<A[ind].size();i++)
if(!Vis[A[ind][i]]){
even=odd;
dfs(A[ind][i]);
}
if(odd) new_[ind]=time_++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
Vis.clear(), A.clear(), new_.clear();
Vis.resize(n), A.resize(n), new_.resize(n);
time_=0, even=1;
for(int i=0;i<n-1;i++)
A[u[i]].push_back(v[i]), A[v[i]].push_back(u[i]);
dfs(0);
return new_;
}
int find_next_station(int s, int t, vector<int> c) {
if(s<c[0]){
if(t<s || t>=c.back()) return c.back();
return *lower_bound(all(c), t);
}
else{
if(t>s || t<=c.front()) return c.front();
return *--upper_bound(all(c), t);
}
}
Compilation message
stations.cpp: In function 'void dfs(int)':
stations.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int i=0;i<A[ind].size();i++)
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
485 ms |
632 KB |
Output is correct |
2 |
Correct |
455 ms |
628 KB |
Output is correct |
3 |
Correct |
949 ms |
488 KB |
Output is correct |
4 |
Correct |
733 ms |
500 KB |
Output is correct |
5 |
Correct |
606 ms |
488 KB |
Output is correct |
6 |
Correct |
469 ms |
488 KB |
Output is correct |
7 |
Correct |
413 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
426 ms |
628 KB |
Output is correct |
2 |
Correct |
576 ms |
512 KB |
Output is correct |
3 |
Correct |
880 ms |
416 KB |
Output is correct |
4 |
Correct |
550 ms |
420 KB |
Output is correct |
5 |
Correct |
509 ms |
508 KB |
Output is correct |
6 |
Correct |
455 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
517 ms |
676 KB |
Output is correct |
2 |
Correct |
431 ms |
628 KB |
Output is correct |
3 |
Correct |
918 ms |
492 KB |
Output is correct |
4 |
Correct |
671 ms |
420 KB |
Output is correct |
5 |
Correct |
502 ms |
504 KB |
Output is correct |
6 |
Correct |
449 ms |
544 KB |
Output is correct |
7 |
Correct |
445 ms |
544 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
5 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
552 ms |
548 KB |
Output is correct |
12 |
Correct |
380 ms |
620 KB |
Output is correct |
13 |
Correct |
449 ms |
672 KB |
Output is correct |
14 |
Correct |
463 ms |
548 KB |
Output is correct |
15 |
Correct |
37 ms |
420 KB |
Output is correct |
16 |
Correct |
48 ms |
544 KB |
Output is correct |
17 |
Correct |
103 ms |
548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
835 ms |
508 KB |
Output is correct |
2 |
Correct |
599 ms |
416 KB |
Output is correct |
3 |
Correct |
513 ms |
416 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
4 ms |
500 KB |
Output is correct |
6 |
Correct |
2 ms |
496 KB |
Output is correct |
7 |
Correct |
482 ms |
504 KB |
Output is correct |
8 |
Correct |
819 ms |
420 KB |
Output is correct |
9 |
Correct |
612 ms |
508 KB |
Output is correct |
10 |
Correct |
554 ms |
508 KB |
Output is correct |
11 |
Correct |
4 ms |
500 KB |
Output is correct |
12 |
Correct |
4 ms |
492 KB |
Output is correct |
13 |
Correct |
5 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
506 ms |
420 KB |
Output is correct |
17 |
Correct |
506 ms |
420 KB |
Output is correct |
18 |
Correct |
399 ms |
420 KB |
Output is correct |
19 |
Correct |
484 ms |
504 KB |
Output is correct |
20 |
Correct |
528 ms |
560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
511 ms |
648 KB |
Output is correct |
2 |
Correct |
432 ms |
632 KB |
Output is correct |
3 |
Correct |
867 ms |
420 KB |
Output is correct |
4 |
Correct |
596 ms |
416 KB |
Output is correct |
5 |
Correct |
585 ms |
420 KB |
Output is correct |
6 |
Correct |
390 ms |
500 KB |
Output is correct |
7 |
Correct |
417 ms |
508 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
388 ms |
620 KB |
Output is correct |
12 |
Correct |
517 ms |
504 KB |
Output is correct |
13 |
Correct |
877 ms |
500 KB |
Output is correct |
14 |
Correct |
601 ms |
416 KB |
Output is correct |
15 |
Correct |
406 ms |
572 KB |
Output is correct |
16 |
Correct |
465 ms |
508 KB |
Output is correct |
17 |
Correct |
607 ms |
420 KB |
Output is correct |
18 |
Correct |
486 ms |
616 KB |
Output is correct |
19 |
Correct |
507 ms |
692 KB |
Output is correct |
20 |
Correct |
538 ms |
556 KB |
Output is correct |
21 |
Correct |
53 ms |
604 KB |
Output is correct |
22 |
Correct |
84 ms |
528 KB |
Output is correct |
23 |
Correct |
120 ms |
500 KB |
Output is correct |
24 |
Correct |
8 ms |
600 KB |
Output is correct |
25 |
Correct |
5 ms |
492 KB |
Output is correct |
26 |
Correct |
4 ms |
492 KB |
Output is correct |
27 |
Correct |
5 ms |
500 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
674 ms |
504 KB |
Output is correct |
30 |
Correct |
522 ms |
420 KB |
Output is correct |
31 |
Correct |
489 ms |
420 KB |
Output is correct |
32 |
Correct |
537 ms |
572 KB |
Output is correct |
33 |
Correct |
580 ms |
620 KB |
Output is correct |
34 |
Correct |
320 ms |
624 KB |
Output is correct |
35 |
Correct |
398 ms |
724 KB |
Output is correct |
36 |
Correct |
384 ms |
716 KB |
Output is correct |
37 |
Correct |
456 ms |
684 KB |
Output is correct |
38 |
Correct |
464 ms |
712 KB |
Output is correct |
39 |
Correct |
453 ms |
640 KB |
Output is correct |
40 |
Correct |
447 ms |
812 KB |
Output is correct |
41 |
Correct |
397 ms |
752 KB |
Output is correct |
42 |
Correct |
57 ms |
692 KB |
Output is correct |
43 |
Correct |
81 ms |
568 KB |
Output is correct |
44 |
Correct |
126 ms |
572 KB |
Output is correct |
45 |
Correct |
174 ms |
548 KB |
Output is correct |
46 |
Correct |
325 ms |
652 KB |
Output is correct |
47 |
Correct |
285 ms |
548 KB |
Output is correct |
48 |
Correct |
52 ms |
712 KB |
Output is correct |
49 |
Correct |
75 ms |
720 KB |
Output is correct |