#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e3+7;
vector<int>V[LIM];
int T[LIM], odw[LIM], l;
void DFS(int x, int v) {
odw[x]=1;
if(v%2==0) {
T[x]=l;
++l;
}
for(auto i : V[x]) if(odw[i]==0) DFS(i, v+1);
if(v%2==1) {
T[x]=l;
++l;
}
}
vector<int>label(int n, int k, vector<int>u, vector<int>v) {
rep(i, n) {
odw[i]=0;
V[i].clear();
}
rep(i, n-1) {
V[u[i]].pb(v[i]);
V[v[i]].pb(u[i]);
}
l=0;
DFS(0, 0);
vector<int>p(n);
rep(i, n) p[i]=T[i];
return p;
}
int find_next_station(int s, int t, vector<int>c) {
if(s==0) {
for(auto i : c) if(i>=t) return i;
} else if(s>=c[0]) {
if(t>s || c.size()>1 && t<c[1]) return c[0];
for(int i=2; i<c.size(); ++i) if(c[i]>t) return c[i-1];
return c.back();
} else {
if(t<s) return c.back();
for(int i=0; i<c.size()-1; ++i) if(c[i]>=t) return c[i];
return c.back();
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:45:24: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
45 | if(t>s || c.size()>1 && t<c[1]) return c[0];
stations.cpp:46:17: 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=2; i<c.size(); ++i) if(c[i]>t) return c[i-1];
| ~^~~~~~~~~
stations.cpp:50:17: 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=0; i<c.size()-1; ++i) if(c[i]>=t) return c[i];
| ~^~~~~~~~~~~
stations.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
53 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
587 ms |
520 KB |
Output is correct |
2 |
Correct |
511 ms |
628 KB |
Output is correct |
3 |
Correct |
1010 ms |
496 KB |
Output is correct |
4 |
Correct |
578 ms |
400 KB |
Output is correct |
5 |
Correct |
579 ms |
400 KB |
Output is correct |
6 |
Correct |
361 ms |
524 KB |
Output is correct |
7 |
Correct |
469 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
416 ms |
516 KB |
Output is correct |
2 |
Correct |
532 ms |
524 KB |
Output is correct |
3 |
Correct |
833 ms |
400 KB |
Output is correct |
4 |
Correct |
586 ms |
400 KB |
Output is correct |
5 |
Correct |
581 ms |
400 KB |
Output is correct |
6 |
Correct |
477 ms |
520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
454 ms |
528 KB |
Output is correct |
2 |
Correct |
478 ms |
508 KB |
Output is correct |
3 |
Correct |
829 ms |
400 KB |
Output is correct |
4 |
Correct |
635 ms |
400 KB |
Output is correct |
5 |
Correct |
477 ms |
520 KB |
Output is correct |
6 |
Correct |
408 ms |
496 KB |
Output is correct |
7 |
Correct |
415 ms |
532 KB |
Output is correct |
8 |
Correct |
1 ms |
476 KB |
Output is correct |
9 |
Correct |
4 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
517 ms |
532 KB |
Output is correct |
12 |
Correct |
428 ms |
620 KB |
Output is correct |
13 |
Correct |
424 ms |
620 KB |
Output is correct |
14 |
Correct |
473 ms |
524 KB |
Output is correct |
15 |
Correct |
36 ms |
596 KB |
Output is correct |
16 |
Correct |
66 ms |
508 KB |
Output is correct |
17 |
Correct |
90 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
745 ms |
512 KB |
Output is correct |
2 |
Correct |
629 ms |
400 KB |
Output is correct |
3 |
Correct |
561 ms |
400 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
0 ms |
476 KB |
Output is correct |
7 |
Correct |
578 ms |
508 KB |
Output is correct |
8 |
Correct |
819 ms |
404 KB |
Output is correct |
9 |
Correct |
499 ms |
400 KB |
Output is correct |
10 |
Correct |
589 ms |
400 KB |
Output is correct |
11 |
Correct |
5 ms |
476 KB |
Output is correct |
12 |
Correct |
6 ms |
588 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
584 KB |
Output is correct |
15 |
Correct |
1 ms |
476 KB |
Output is correct |
16 |
Correct |
417 ms |
644 KB |
Output is correct |
17 |
Correct |
425 ms |
400 KB |
Output is correct |
18 |
Correct |
425 ms |
536 KB |
Output is correct |
19 |
Correct |
576 ms |
520 KB |
Output is correct |
20 |
Correct |
515 ms |
516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
587 ms |
532 KB |
Output is correct |
2 |
Correct |
396 ms |
520 KB |
Output is correct |
3 |
Correct |
954 ms |
404 KB |
Output is correct |
4 |
Correct |
714 ms |
400 KB |
Output is correct |
5 |
Correct |
543 ms |
400 KB |
Output is correct |
6 |
Correct |
475 ms |
504 KB |
Output is correct |
7 |
Correct |
455 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
400 KB |
Output is correct |
11 |
Correct |
502 ms |
508 KB |
Output is correct |
12 |
Correct |
510 ms |
512 KB |
Output is correct |
13 |
Correct |
768 ms |
400 KB |
Output is correct |
14 |
Correct |
573 ms |
476 KB |
Output is correct |
15 |
Correct |
565 ms |
400 KB |
Output is correct |
16 |
Correct |
433 ms |
532 KB |
Output is correct |
17 |
Correct |
490 ms |
516 KB |
Output is correct |
18 |
Correct |
370 ms |
612 KB |
Output is correct |
19 |
Correct |
427 ms |
644 KB |
Output is correct |
20 |
Correct |
450 ms |
532 KB |
Output is correct |
21 |
Correct |
54 ms |
596 KB |
Output is correct |
22 |
Correct |
73 ms |
576 KB |
Output is correct |
23 |
Correct |
92 ms |
716 KB |
Output is correct |
24 |
Correct |
4 ms |
468 KB |
Output is correct |
25 |
Correct |
5 ms |
476 KB |
Output is correct |
26 |
Correct |
5 ms |
480 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
0 ms |
468 KB |
Output is correct |
29 |
Correct |
548 ms |
520 KB |
Output is correct |
30 |
Correct |
424 ms |
404 KB |
Output is correct |
31 |
Correct |
403 ms |
400 KB |
Output is correct |
32 |
Correct |
388 ms |
512 KB |
Output is correct |
33 |
Correct |
556 ms |
400 KB |
Output is correct |
34 |
Correct |
352 ms |
496 KB |
Output is correct |
35 |
Correct |
410 ms |
520 KB |
Output is correct |
36 |
Correct |
461 ms |
620 KB |
Output is correct |
37 |
Correct |
456 ms |
716 KB |
Output is correct |
38 |
Correct |
430 ms |
632 KB |
Output is correct |
39 |
Correct |
372 ms |
600 KB |
Output is correct |
40 |
Correct |
445 ms |
640 KB |
Output is correct |
41 |
Correct |
396 ms |
756 KB |
Output is correct |
42 |
Correct |
68 ms |
548 KB |
Output is correct |
43 |
Correct |
88 ms |
728 KB |
Output is correct |
44 |
Correct |
130 ms |
528 KB |
Output is correct |
45 |
Correct |
162 ms |
504 KB |
Output is correct |
46 |
Correct |
307 ms |
528 KB |
Output is correct |
47 |
Correct |
305 ms |
508 KB |
Output is correct |
48 |
Correct |
57 ms |
704 KB |
Output is correct |
49 |
Correct |
52 ms |
652 KB |
Output is correct |