#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
int cnt;
vector<vector<int>> g;
vector<int> in, out, d;
void dfs(int cur, int dep){
if (d[cur] != -1) return;
d[cur] = dep;
in[cur] = cnt++;
for (int next : g[cur]) dfs(next, dep+1);
out[cur] = cnt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
g.resize(0);
g.resize(n);
for (int i=0; i<n-1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
in.resize(0); out.resize(0); d.resize(0);
in.resize(n); out.resize(n); d.resize(n, -1);
cnt = 0;
dfs(0, 0);
/*for (int x : in) cout << x << " ";
cout << "\n";
for (int x : out) cout << x << " ";
cout << "\n";*/
vector<int> l(n, 0);
for (int i=0; i<n; i++){
if (d[i] % 2) l[i] = out[i];
else l[i] = in[i];
}
//return l;
vector<int> w = l;
sort(w.begin(), w.end());
unordered_map<int,int> m;
for (int i=0; i<n; i++) m[w[i]] = i;
for (int i=0; i<n; i++) l[i] = m[l[i]];
/*for (int x : l) cout << x << " ";
cout << "\n";*/
return l;
}
int find_next_station(int s, int t, vector<int> c){
if (c.size() == 1) return c[0];
if (s == 0){
vector<int> d(c.size());
for (int i=0; i<c.size(); i++){
if (i == 0) d[i] = s+1;
else d[i] = c[i-1]+1;
if (d[i] <= t && t <= c[i]) return c[i];
}
}
else {
int x = 2000;
for (int y : c) x = min(x, y);
if (s < x){
vector<int> d(c.size()-1);
for (int i=0; i<c.size()-1; i++){
if (i == 0) d[i] = s+1;
else d[i] = c[i-1]+1;
if (d[i] <= t && t <= c[i]) return c[i];
}
return c.back();
}
else {
vector<int> d(c.size());
for (int i=c.size()-1; i>=0; i--){
if (i == c.size()-1) d[i] = s-1;
else d[i] = c[i+1]-1;
if (c[i] <= t && t <= d[i]) return c[i];
}
return c[0];
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i=0; i<c.size(); i++){
| ~^~~~~~~~~
stations.cpp:63:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int i=0; i<c.size()-1; i++){
| ~^~~~~~~~~~~
stations.cpp:73:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | if (i == c.size()-1) d[i] = s-1;
| ~~^~~~~~~~~~~~~
stations.cpp:80:1: warning: control reaches end of non-void function [-Wreturn-type]
80 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
347 ms |
940 KB |
Output is correct |
2 |
Correct |
342 ms |
940 KB |
Output is correct |
3 |
Correct |
599 ms |
684 KB |
Output is correct |
4 |
Correct |
448 ms |
936 KB |
Output is correct |
5 |
Correct |
432 ms |
684 KB |
Output is correct |
6 |
Correct |
326 ms |
940 KB |
Output is correct |
7 |
Correct |
305 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
776 KB |
Output is correct |
10 |
Correct |
0 ms |
1028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
295 ms |
940 KB |
Output is correct |
2 |
Correct |
373 ms |
684 KB |
Output is correct |
3 |
Correct |
658 ms |
684 KB |
Output is correct |
4 |
Correct |
461 ms |
688 KB |
Output is correct |
5 |
Correct |
399 ms |
936 KB |
Output is correct |
6 |
Correct |
323 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
359 ms |
940 KB |
Output is correct |
2 |
Correct |
317 ms |
940 KB |
Output is correct |
3 |
Correct |
674 ms |
684 KB |
Output is correct |
4 |
Correct |
442 ms |
684 KB |
Output is correct |
5 |
Correct |
370 ms |
684 KB |
Output is correct |
6 |
Correct |
350 ms |
940 KB |
Output is correct |
7 |
Correct |
298 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
413 ms |
772 KB |
Output is correct |
12 |
Correct |
305 ms |
1016 KB |
Output is correct |
13 |
Correct |
327 ms |
1020 KB |
Output is correct |
14 |
Correct |
298 ms |
684 KB |
Output is correct |
15 |
Correct |
31 ms |
768 KB |
Output is correct |
16 |
Correct |
41 ms |
772 KB |
Output is correct |
17 |
Correct |
64 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
637 ms |
684 KB |
Output is correct |
2 |
Correct |
474 ms |
684 KB |
Output is correct |
3 |
Correct |
458 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
2 ms |
780 KB |
Output is correct |
6 |
Correct |
0 ms |
776 KB |
Output is correct |
7 |
Correct |
415 ms |
772 KB |
Output is correct |
8 |
Correct |
609 ms |
684 KB |
Output is correct |
9 |
Correct |
476 ms |
684 KB |
Output is correct |
10 |
Correct |
448 ms |
684 KB |
Output is correct |
11 |
Correct |
3 ms |
776 KB |
Output is correct |
12 |
Correct |
2 ms |
768 KB |
Output is correct |
13 |
Correct |
2 ms |
1016 KB |
Output is correct |
14 |
Correct |
1 ms |
776 KB |
Output is correct |
15 |
Correct |
0 ms |
776 KB |
Output is correct |
16 |
Correct |
353 ms |
688 KB |
Output is correct |
17 |
Correct |
366 ms |
684 KB |
Output is correct |
18 |
Correct |
377 ms |
684 KB |
Output is correct |
19 |
Correct |
356 ms |
684 KB |
Output is correct |
20 |
Correct |
361 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
362 ms |
940 KB |
Output is correct |
2 |
Correct |
298 ms |
940 KB |
Output is correct |
3 |
Correct |
658 ms |
684 KB |
Output is correct |
4 |
Correct |
467 ms |
684 KB |
Output is correct |
5 |
Correct |
361 ms |
684 KB |
Output is correct |
6 |
Correct |
317 ms |
940 KB |
Output is correct |
7 |
Correct |
315 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
764 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
324 ms |
684 KB |
Output is correct |
12 |
Correct |
325 ms |
684 KB |
Output is correct |
13 |
Correct |
627 ms |
684 KB |
Output is correct |
14 |
Correct |
461 ms |
684 KB |
Output is correct |
15 |
Correct |
369 ms |
684 KB |
Output is correct |
16 |
Correct |
302 ms |
684 KB |
Output is correct |
17 |
Correct |
395 ms |
684 KB |
Output is correct |
18 |
Correct |
312 ms |
1036 KB |
Output is correct |
19 |
Correct |
311 ms |
1276 KB |
Output is correct |
20 |
Correct |
290 ms |
684 KB |
Output is correct |
21 |
Correct |
27 ms |
764 KB |
Output is correct |
22 |
Correct |
42 ms |
716 KB |
Output is correct |
23 |
Correct |
63 ms |
684 KB |
Output is correct |
24 |
Correct |
3 ms |
768 KB |
Output is correct |
25 |
Correct |
4 ms |
768 KB |
Output is correct |
26 |
Correct |
3 ms |
768 KB |
Output is correct |
27 |
Correct |
1 ms |
812 KB |
Output is correct |
28 |
Correct |
1 ms |
776 KB |
Output is correct |
29 |
Correct |
343 ms |
684 KB |
Output is correct |
30 |
Correct |
376 ms |
688 KB |
Output is correct |
31 |
Correct |
347 ms |
684 KB |
Output is correct |
32 |
Correct |
348 ms |
940 KB |
Output is correct |
33 |
Correct |
384 ms |
684 KB |
Output is correct |
34 |
Correct |
215 ms |
684 KB |
Output is correct |
35 |
Correct |
289 ms |
1032 KB |
Output is correct |
36 |
Correct |
290 ms |
940 KB |
Output is correct |
37 |
Correct |
312 ms |
1024 KB |
Output is correct |
38 |
Correct |
317 ms |
1028 KB |
Output is correct |
39 |
Correct |
319 ms |
1272 KB |
Output is correct |
40 |
Correct |
296 ms |
1036 KB |
Output is correct |
41 |
Correct |
349 ms |
796 KB |
Output is correct |
42 |
Correct |
34 ms |
768 KB |
Output is correct |
43 |
Correct |
68 ms |
744 KB |
Output is correct |
44 |
Correct |
92 ms |
988 KB |
Output is correct |
45 |
Correct |
104 ms |
684 KB |
Output is correct |
46 |
Correct |
220 ms |
684 KB |
Output is correct |
47 |
Correct |
209 ms |
684 KB |
Output is correct |
48 |
Correct |
35 ms |
744 KB |
Output is correct |
49 |
Correct |
28 ms |
952 KB |
Output is correct |