#include "stations.h"
#include <bits/stdc++.h>
#define N 1005
using namespace std;
int tin[N],tout[N];
int d[N];
vector<int> adj[N];
int timer = 0;
void dfs(int v,int par){
tin[v] = timer++;
for(auto u:adj[v]){
if(u == par)
continue;
d[u] = d[v] + 1;
dfs(u,v);
}
tout[v] = timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for(int i = 0;i<n;i++){
adj[i].clear();
}
timer = 0;
for(int i = 0;i<n-1;i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0,-1);
vector<int> ret(n,0);
vector<int> compress;
for(int i = 0;i<n;i++){
if(d[i] & 1)
ret[i] = tin[i];
else ret[i] = tout[i];
compress.push_back(ret[i]);
}
sort(compress.begin(),compress.end());
for(int i = 0;i<n;i++){
ret[i] = lower_bound(compress.begin(),compress.end(),ret[i]) - compress.begin();
}
return ret;
}
int find_next_station(int s, int t, vector<int> c){
if(c.size() == 1)
return c[0];
if(c[0] > s){
int l = s;
int r = c[c.size()-2];
if(t < l || t > r)
return c.back();
int x = 1e9;
for(int i = 0;i<c.size()-1;i++){
if(c[i] >= t)
x = min(x,c[i]);
}
return x;
}
else{
int l = c[1];
int r = s;
if(t < l || t > r)
return c[0];
int x = 0;
for(int i = 1;i<c.size();i++){
if(c[i] <= t)
x = max(x,c[i]);
}
return x;
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i = 0;i<c.size()-1;i++){
| ~^~~~~~~~~~~
stations.cpp:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i = 1;i<c.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
390 ms |
656 KB |
Output is correct |
2 |
Correct |
370 ms |
660 KB |
Output is correct |
3 |
Correct |
633 ms |
516 KB |
Output is correct |
4 |
Correct |
492 ms |
416 KB |
Output is correct |
5 |
Correct |
466 ms |
524 KB |
Output is correct |
6 |
Correct |
315 ms |
536 KB |
Output is correct |
7 |
Correct |
321 ms |
532 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
348 ms |
528 KB |
Output is correct |
2 |
Correct |
433 ms |
528 KB |
Output is correct |
3 |
Correct |
522 ms |
548 KB |
Output is correct |
4 |
Correct |
459 ms |
528 KB |
Output is correct |
5 |
Correct |
380 ms |
524 KB |
Output is correct |
6 |
Correct |
349 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
341 ms |
640 KB |
Output is correct |
2 |
Correct |
312 ms |
548 KB |
Output is correct |
3 |
Correct |
581 ms |
532 KB |
Output is correct |
4 |
Correct |
376 ms |
544 KB |
Output is correct |
5 |
Correct |
411 ms |
548 KB |
Output is correct |
6 |
Correct |
313 ms |
656 KB |
Output is correct |
7 |
Correct |
310 ms |
548 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
0 ms |
620 KB |
Output is correct |
11 |
Correct |
377 ms |
532 KB |
Output is correct |
12 |
Correct |
299 ms |
652 KB |
Output is correct |
13 |
Correct |
323 ms |
676 KB |
Output is correct |
14 |
Correct |
238 ms |
532 KB |
Output is correct |
15 |
Correct |
34 ms |
620 KB |
Output is correct |
16 |
Correct |
47 ms |
596 KB |
Output is correct |
17 |
Correct |
72 ms |
728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
581 ms |
524 KB |
Output is correct |
2 |
Correct |
484 ms |
420 KB |
Output is correct |
3 |
Correct |
407 ms |
548 KB |
Output is correct |
4 |
Correct |
1 ms |
628 KB |
Output is correct |
5 |
Correct |
3 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
437 ms |
544 KB |
Output is correct |
8 |
Correct |
609 ms |
524 KB |
Output is correct |
9 |
Correct |
444 ms |
420 KB |
Output is correct |
10 |
Correct |
411 ms |
548 KB |
Output is correct |
11 |
Correct |
2 ms |
500 KB |
Output is correct |
12 |
Correct |
3 ms |
492 KB |
Output is correct |
13 |
Correct |
2 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
346 ms |
416 KB |
Output is correct |
17 |
Correct |
354 ms |
548 KB |
Output is correct |
18 |
Correct |
354 ms |
548 KB |
Output is correct |
19 |
Correct |
334 ms |
544 KB |
Output is correct |
20 |
Correct |
360 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
357 ms |
656 KB |
Output is correct |
2 |
Correct |
300 ms |
668 KB |
Output is correct |
3 |
Correct |
547 ms |
548 KB |
Output is correct |
4 |
Correct |
442 ms |
520 KB |
Output is correct |
5 |
Correct |
334 ms |
592 KB |
Output is correct |
6 |
Correct |
349 ms |
548 KB |
Output is correct |
7 |
Correct |
286 ms |
544 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
2 ms |
628 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
300 ms |
528 KB |
Output is correct |
12 |
Correct |
300 ms |
548 KB |
Output is correct |
13 |
Correct |
615 ms |
544 KB |
Output is correct |
14 |
Correct |
423 ms |
516 KB |
Output is correct |
15 |
Correct |
382 ms |
544 KB |
Output is correct |
16 |
Correct |
324 ms |
548 KB |
Output is correct |
17 |
Correct |
410 ms |
544 KB |
Output is correct |
18 |
Correct |
323 ms |
652 KB |
Output is correct |
19 |
Correct |
319 ms |
648 KB |
Output is correct |
20 |
Correct |
324 ms |
548 KB |
Output is correct |
21 |
Correct |
40 ms |
576 KB |
Output is correct |
22 |
Correct |
52 ms |
572 KB |
Output is correct |
23 |
Correct |
69 ms |
672 KB |
Output is correct |
24 |
Correct |
3 ms |
496 KB |
Output is correct |
25 |
Correct |
2 ms |
628 KB |
Output is correct |
26 |
Correct |
1 ms |
628 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
351 ms |
544 KB |
Output is correct |
30 |
Correct |
349 ms |
528 KB |
Output is correct |
31 |
Correct |
329 ms |
416 KB |
Output is correct |
32 |
Correct |
341 ms |
420 KB |
Output is correct |
33 |
Correct |
300 ms |
528 KB |
Output is correct |
34 |
Correct |
225 ms |
652 KB |
Output is correct |
35 |
Correct |
258 ms |
652 KB |
Output is correct |
36 |
Correct |
326 ms |
660 KB |
Output is correct |
37 |
Correct |
350 ms |
720 KB |
Output is correct |
38 |
Correct |
240 ms |
644 KB |
Output is correct |
39 |
Correct |
334 ms |
788 KB |
Output is correct |
40 |
Correct |
318 ms |
528 KB |
Output is correct |
41 |
Correct |
315 ms |
640 KB |
Output is correct |
42 |
Correct |
52 ms |
544 KB |
Output is correct |
43 |
Correct |
74 ms |
700 KB |
Output is correct |
44 |
Correct |
90 ms |
544 KB |
Output is correct |
45 |
Correct |
87 ms |
604 KB |
Output is correct |
46 |
Correct |
225 ms |
544 KB |
Output is correct |
47 |
Correct |
190 ms |
544 KB |
Output is correct |
48 |
Correct |
44 ms |
720 KB |
Output is correct |
49 |
Correct |
43 ms |
824 KB |
Output is correct |