#include "stations.h"
#include <bits/stdc++.h>
#define MAX_N 1000
using namespace std;
int l;
int lc[MAX_N], rc[MAX_N];
vector<int> edges[MAX_N];
vector<int> labels, c;
void dfs( int u, int p, int d ) {
if ( d == 0 )
labels[u] = l / 2;
l++;
for ( int v: edges[u] ) {
if ( v != p )
dfs( v, u, 1 - d );
}
if ( d == 1 )
labels[u] = l / 2;
l++;
}
vector<int> label( int n, int k, vector<int> u, vector<int> v ) {
for ( int i = 0; i < n; i++ )
edges[i].clear();
for ( int i = 0; i < n - 1; i++ ) {
edges[u[i]].push_back( v[i] );
edges[v[i]].push_back( u[i] );
}
labels.resize( n );
l = 0;
dfs( 0, -1, 0 );
return labels;
}
int find_next_station( int s, int t, vector<int> e ) {
int ls, rs, ds, p, l, h, i;
l = h = 0;
for ( int x: e ) {
if ( x < s )
l++;
else
h++;
}
ds = (l == 0 ? 0 : 1);
s = s * 2;
t = t * 2;
p = 0;
c.clear();
if ( ds == 0 ) {
if ( s == 0 )
c = e;
else {
p = e.back();
for ( i = 0; i < e.size() - 1; i++ )
c.push_back( e[i] );
}
ls = s;
rs = c.back() * 2 + 1;
for ( i = 0; i < c.size(); i++ )
rc[i] = c[i] * 2;
lc[0] = ls + 1;
for ( i = 1; i < c.size(); i++ )
lc[i] = rc[i - 1] + 1;
} else {
if ( s == 0 )
c = e;
else {
p = e.front();
for ( i = 1; i < e.size(); i++ )
c.push_back( e[i] );
}
ls = c.front() * 2 - 1;
rs = s;
for ( i = 0; i < c.size(); i++ )
lc[i] = c[i] * 2;
for ( i = 0; i + 1 < c.size(); i++ )
rc[i] = lc[i + 1] - 1;
rc[c.size() - 1] = rs - 1;
}
for ( i = 0; i < c.size(); i++ ) {
if ( lc[i] <= t && t <= rc[i] )
return c[i];
}
return p;
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:62:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for ( i = 0; i < e.size() - 1; i++ )
| ~~^~~~~~~~~~~~~~
stations.cpp:67:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for ( i = 0; i < c.size(); i++ )
| ~~^~~~~~~~~~
stations.cpp:70:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for ( i = 1; i < c.size(); i++ )
| ~~^~~~~~~~~~
stations.cpp:77:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for ( i = 1; i < e.size(); i++ )
| ~~^~~~~~~~~~
stations.cpp:82:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for ( i = 0; i < c.size(); i++ )
| ~~^~~~~~~~~~
stations.cpp:84:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for ( i = 0; i + 1 < c.size(); i++ )
| ~~~~~~^~~~~~~~~~
stations.cpp:89:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for ( i = 0; i < c.size(); i++ ) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
526 ms |
788 KB |
Output is correct |
2 |
Correct |
467 ms |
652 KB |
Output is correct |
3 |
Correct |
1033 ms |
548 KB |
Output is correct |
4 |
Correct |
756 ms |
532 KB |
Output is correct |
5 |
Correct |
660 ms |
544 KB |
Output is correct |
6 |
Correct |
431 ms |
660 KB |
Output is correct |
7 |
Correct |
452 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
459 ms |
672 KB |
Output is correct |
2 |
Correct |
523 ms |
528 KB |
Output is correct |
3 |
Correct |
987 ms |
416 KB |
Output is correct |
4 |
Correct |
769 ms |
416 KB |
Output is correct |
5 |
Correct |
718 ms |
416 KB |
Output is correct |
6 |
Correct |
494 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
531 ms |
652 KB |
Output is correct |
2 |
Correct |
463 ms |
520 KB |
Output is correct |
3 |
Correct |
894 ms |
420 KB |
Output is correct |
4 |
Correct |
631 ms |
528 KB |
Output is correct |
5 |
Correct |
675 ms |
416 KB |
Output is correct |
6 |
Correct |
422 ms |
652 KB |
Output is correct |
7 |
Correct |
433 ms |
548 KB |
Output is correct |
8 |
Correct |
3 ms |
496 KB |
Output is correct |
9 |
Correct |
5 ms |
500 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
677 ms |
416 KB |
Output is correct |
12 |
Correct |
479 ms |
736 KB |
Output is correct |
13 |
Correct |
464 ms |
664 KB |
Output is correct |
14 |
Correct |
491 ms |
544 KB |
Output is correct |
15 |
Correct |
60 ms |
748 KB |
Output is correct |
16 |
Correct |
67 ms |
748 KB |
Output is correct |
17 |
Correct |
117 ms |
676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
829 ms |
416 KB |
Output is correct |
2 |
Correct |
697 ms |
416 KB |
Output is correct |
3 |
Correct |
587 ms |
528 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
500 KB |
Output is correct |
7 |
Correct |
652 ms |
656 KB |
Output is correct |
8 |
Correct |
820 ms |
656 KB |
Output is correct |
9 |
Correct |
755 ms |
416 KB |
Output is correct |
10 |
Correct |
648 ms |
416 KB |
Output is correct |
11 |
Correct |
6 ms |
548 KB |
Output is correct |
12 |
Correct |
4 ms |
488 KB |
Output is correct |
13 |
Correct |
6 ms |
696 KB |
Output is correct |
14 |
Correct |
4 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
477 ms |
524 KB |
Output is correct |
17 |
Correct |
457 ms |
656 KB |
Output is correct |
18 |
Correct |
804 ms |
420 KB |
Output is correct |
19 |
Correct |
546 ms |
524 KB |
Output is correct |
20 |
Correct |
536 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
628 ms |
812 KB |
Output is correct |
2 |
Correct |
350 ms |
636 KB |
Output is correct |
3 |
Correct |
929 ms |
524 KB |
Output is correct |
4 |
Correct |
788 ms |
416 KB |
Output is correct |
5 |
Correct |
540 ms |
708 KB |
Output is correct |
6 |
Correct |
515 ms |
528 KB |
Output is correct |
7 |
Correct |
475 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
608 KB |
Output is correct |
10 |
Correct |
1 ms |
496 KB |
Output is correct |
11 |
Correct |
445 ms |
524 KB |
Output is correct |
12 |
Correct |
626 ms |
544 KB |
Output is correct |
13 |
Correct |
1008 ms |
416 KB |
Output is correct |
14 |
Correct |
761 ms |
528 KB |
Output is correct |
15 |
Correct |
628 ms |
416 KB |
Output is correct |
16 |
Correct |
419 ms |
548 KB |
Output is correct |
17 |
Correct |
533 ms |
544 KB |
Output is correct |
18 |
Correct |
578 ms |
624 KB |
Output is correct |
19 |
Correct |
490 ms |
652 KB |
Output is correct |
20 |
Correct |
547 ms |
524 KB |
Output is correct |
21 |
Correct |
90 ms |
420 KB |
Output is correct |
22 |
Correct |
84 ms |
672 KB |
Output is correct |
23 |
Correct |
116 ms |
804 KB |
Output is correct |
24 |
Correct |
7 ms |
620 KB |
Output is correct |
25 |
Correct |
5 ms |
652 KB |
Output is correct |
26 |
Correct |
5 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
500 KB |
Output is correct |
29 |
Correct |
443 ms |
532 KB |
Output is correct |
30 |
Correct |
565 ms |
432 KB |
Output is correct |
31 |
Correct |
532 ms |
416 KB |
Output is correct |
32 |
Correct |
456 ms |
528 KB |
Output is correct |
33 |
Correct |
588 ms |
528 KB |
Output is correct |
34 |
Correct |
315 ms |
620 KB |
Output is correct |
35 |
Correct |
420 ms |
656 KB |
Output is correct |
36 |
Correct |
409 ms |
656 KB |
Output is correct |
37 |
Correct |
481 ms |
764 KB |
Output is correct |
38 |
Correct |
445 ms |
652 KB |
Output is correct |
39 |
Correct |
410 ms |
572 KB |
Output is correct |
40 |
Correct |
360 ms |
660 KB |
Output is correct |
41 |
Correct |
385 ms |
668 KB |
Output is correct |
42 |
Correct |
52 ms |
672 KB |
Output is correct |
43 |
Correct |
112 ms |
724 KB |
Output is correct |
44 |
Correct |
115 ms |
656 KB |
Output is correct |
45 |
Correct |
186 ms |
672 KB |
Output is correct |
46 |
Correct |
321 ms |
576 KB |
Output is correct |
47 |
Correct |
315 ms |
548 KB |
Output is correct |
48 |
Correct |
54 ms |
716 KB |
Output is correct |
49 |
Correct |
41 ms |
764 KB |
Output is correct |