#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1005;
vector<int> g[MAX];
int in[MAX], out[MAX];
int col[MAX];
int t = 0;
void dfs(int node, int p){
col[node] = col[p] ^ 1;
in[node] = ++t;
for(int to : g[node]){
if(to == p) continue;
dfs(to, node);
}
out[node] = t++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for(int i = 0; i < n; i++) g[i].clear();
for(int i = 0; i < n - 1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs(1, 1);
vector<int> L;
map<int, int> mp;
for(int i = 0; i < n; i++){
if(col[i]){
L.push_back(in[i]);
mp[in[i]];
}
else{
L.push_back(out[i]);
mp[out[i]];
}
}
int t = 0;
for(auto a : mp) mp[a.first] = t++;
for(int i = 0; i < n; i++){
L[i] = mp[L[i]];
}
return L;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(), c.end());
if(s < c[0]){
int in = s + 1;
for(int i = 0; i < c.size() - 1; i++){
if(in <= t && t <= c[i]){
return c[i];
}
in = c[i] + 1;
}
return c.back();
}
else{
sort(c.rbegin(), c.rend());
int out = s - 1;
for(int i = 0; i < c.size() - 1; i++){
if(c[i] <= t && t <= out) return c[i];
out = c[i] - 1;
}
return c.back();
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i = 0; i < c.size() - 1; i++){
| ~~^~~~~~~~~~~~~~
stations.cpp:62:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i = 0; i < c.size() - 1; i++){
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
361 ms |
940 KB |
Output is correct |
2 |
Correct |
235 ms |
940 KB |
Output is correct |
3 |
Correct |
495 ms |
684 KB |
Output is correct |
4 |
Correct |
391 ms |
684 KB |
Output is correct |
5 |
Correct |
361 ms |
684 KB |
Output is correct |
6 |
Correct |
255 ms |
940 KB |
Output is correct |
7 |
Correct |
247 ms |
684 KB |
Output is correct |
8 |
Correct |
0 ms |
776 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
237 ms |
688 KB |
Output is correct |
2 |
Correct |
326 ms |
684 KB |
Output is correct |
3 |
Correct |
513 ms |
684 KB |
Output is correct |
4 |
Correct |
393 ms |
684 KB |
Output is correct |
5 |
Correct |
330 ms |
684 KB |
Output is correct |
6 |
Correct |
256 ms |
944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
940 KB |
Output is correct |
2 |
Correct |
274 ms |
940 KB |
Output is correct |
3 |
Correct |
517 ms |
684 KB |
Output is correct |
4 |
Correct |
394 ms |
684 KB |
Output is correct |
5 |
Correct |
337 ms |
684 KB |
Output is correct |
6 |
Correct |
232 ms |
940 KB |
Output is correct |
7 |
Correct |
246 ms |
952 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
776 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
11 |
Correct |
340 ms |
684 KB |
Output is correct |
12 |
Correct |
223 ms |
1048 KB |
Output is correct |
13 |
Correct |
244 ms |
1188 KB |
Output is correct |
14 |
Correct |
264 ms |
684 KB |
Output is correct |
15 |
Correct |
31 ms |
764 KB |
Output is correct |
16 |
Correct |
27 ms |
772 KB |
Output is correct |
17 |
Correct |
71 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
498 ms |
688 KB |
Output is correct |
2 |
Correct |
372 ms |
684 KB |
Output is correct |
3 |
Correct |
329 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
1028 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
0 ms |
768 KB |
Output is correct |
7 |
Correct |
314 ms |
684 KB |
Output is correct |
8 |
Correct |
460 ms |
684 KB |
Output is correct |
9 |
Correct |
355 ms |
684 KB |
Output is correct |
10 |
Correct |
307 ms |
684 KB |
Output is correct |
11 |
Correct |
2 ms |
768 KB |
Output is correct |
12 |
Correct |
3 ms |
768 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
764 KB |
Output is correct |
15 |
Correct |
0 ms |
776 KB |
Output is correct |
16 |
Correct |
287 ms |
688 KB |
Output is correct |
17 |
Correct |
275 ms |
684 KB |
Output is correct |
18 |
Correct |
277 ms |
684 KB |
Output is correct |
19 |
Correct |
314 ms |
684 KB |
Output is correct |
20 |
Correct |
302 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
291 ms |
940 KB |
Output is correct |
2 |
Correct |
244 ms |
940 KB |
Output is correct |
3 |
Correct |
465 ms |
684 KB |
Output is correct |
4 |
Correct |
354 ms |
684 KB |
Output is correct |
5 |
Correct |
335 ms |
684 KB |
Output is correct |
6 |
Correct |
234 ms |
940 KB |
Output is correct |
7 |
Correct |
258 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
776 KB |
Output is correct |
9 |
Correct |
2 ms |
1016 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
11 |
Correct |
254 ms |
684 KB |
Output is correct |
12 |
Correct |
345 ms |
688 KB |
Output is correct |
13 |
Correct |
460 ms |
684 KB |
Output is correct |
14 |
Correct |
384 ms |
688 KB |
Output is correct |
15 |
Correct |
309 ms |
684 KB |
Output is correct |
16 |
Correct |
254 ms |
684 KB |
Output is correct |
17 |
Correct |
348 ms |
684 KB |
Output is correct |
18 |
Correct |
254 ms |
1044 KB |
Output is correct |
19 |
Correct |
255 ms |
1052 KB |
Output is correct |
20 |
Correct |
239 ms |
684 KB |
Output is correct |
21 |
Correct |
30 ms |
768 KB |
Output is correct |
22 |
Correct |
28 ms |
764 KB |
Output is correct |
23 |
Correct |
47 ms |
768 KB |
Output is correct |
24 |
Correct |
3 ms |
768 KB |
Output is correct |
25 |
Correct |
2 ms |
776 KB |
Output is correct |
26 |
Correct |
1 ms |
768 KB |
Output is correct |
27 |
Correct |
2 ms |
776 KB |
Output is correct |
28 |
Correct |
0 ms |
776 KB |
Output is correct |
29 |
Correct |
278 ms |
800 KB |
Output is correct |
30 |
Correct |
290 ms |
684 KB |
Output is correct |
31 |
Correct |
321 ms |
684 KB |
Output is correct |
32 |
Correct |
288 ms |
684 KB |
Output is correct |
33 |
Correct |
282 ms |
684 KB |
Output is correct |
34 |
Correct |
173 ms |
972 KB |
Output is correct |
35 |
Correct |
263 ms |
940 KB |
Output is correct |
36 |
Correct |
233 ms |
944 KB |
Output is correct |
37 |
Correct |
240 ms |
1064 KB |
Output is correct |
38 |
Correct |
245 ms |
1072 KB |
Output is correct |
39 |
Correct |
267 ms |
1056 KB |
Output is correct |
40 |
Correct |
257 ms |
1044 KB |
Output is correct |
41 |
Correct |
276 ms |
1304 KB |
Output is correct |
42 |
Correct |
27 ms |
776 KB |
Output is correct |
43 |
Correct |
55 ms |
768 KB |
Output is correct |
44 |
Correct |
69 ms |
744 KB |
Output is correct |
45 |
Correct |
80 ms |
1192 KB |
Output is correct |
46 |
Correct |
168 ms |
684 KB |
Output is correct |
47 |
Correct |
183 ms |
684 KB |
Output is correct |
48 |
Correct |
31 ms |
956 KB |
Output is correct |
49 |
Correct |
26 ms |
1024 KB |
Output is correct |