#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int MX=1005;
vector<int> adj[MX];
int cnt=0;
vector<int> tin, tout, dep;
void dfs(int v, int p) {
tin[v]=cnt++;
for(auto u:adj[v]) {
if(u==p) continue;
dep[u]=dep[v]+1;
dfs(u,v);
}
tout[v]=cnt++;
}
std::vector<int> label(int N, int K, std::vector<int> u, std::vector<int> v) {
for(int i=0;i<N;i++) adj[i].clear();
for(int i=0;i<N-1;i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
cnt=0;
tin.assign(N,0);
tout.assign(N,0);
dep.assign(N,0);
dfs(0,-1);
vector<pair<int,int>> res;
for(int i=0;i<N;i++) {
if(dep[i]&1) res.push_back({tin[i],i});
else res.push_back({tout[i],i});
}
sort(res.begin(),res.end());
vector<int> ans(N);
for(int i=0;i<N;i++) ans[res[i].second]=i;
return ans;
}
int find_next_station(int s, int t, std::vector<int> c) {
bool ok=1;
for(auto x:c) ok&=s<=x;
if(ok) { // s itu tin
int cur=s;
for(int i=0;i+1<c.size();i++) {
if(cur<t && t<=c[i]) { // c_i is tout
return c[i];
}
cur=c[i];
}
return c.back();
} else { // s itu tout
c.push_back(s);
for(int i=1;i+1<c.size();i++) {
if(c[i]<=t && t<c[i+1]) {
return c[i];
}
}
return c[0];
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i=0;i+1<c.size();i++) {
| ~~~^~~~~~~~~
stations.cpp:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i=1;i+1<c.size();i++) {
| ~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
371 ms |
684 KB |
Output is correct |
2 |
Correct |
296 ms |
684 KB |
Output is correct |
3 |
Correct |
627 ms |
684 KB |
Output is correct |
4 |
Correct |
423 ms |
684 KB |
Output is correct |
5 |
Correct |
401 ms |
684 KB |
Output is correct |
6 |
Correct |
332 ms |
684 KB |
Output is correct |
7 |
Correct |
296 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
290 ms |
684 KB |
Output is correct |
2 |
Correct |
395 ms |
684 KB |
Output is correct |
3 |
Correct |
581 ms |
684 KB |
Output is correct |
4 |
Correct |
399 ms |
684 KB |
Output is correct |
5 |
Correct |
392 ms |
944 KB |
Output is correct |
6 |
Correct |
306 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
351 ms |
1200 KB |
Output is correct |
2 |
Correct |
310 ms |
940 KB |
Output is correct |
3 |
Correct |
568 ms |
684 KB |
Output is correct |
4 |
Correct |
432 ms |
684 KB |
Output is correct |
5 |
Correct |
395 ms |
696 KB |
Output is correct |
6 |
Correct |
300 ms |
684 KB |
Output is correct |
7 |
Correct |
283 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
776 KB |
Output is correct |
9 |
Correct |
1 ms |
776 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
393 ms |
684 KB |
Output is correct |
12 |
Correct |
298 ms |
788 KB |
Output is correct |
13 |
Correct |
317 ms |
1188 KB |
Output is correct |
14 |
Correct |
290 ms |
688 KB |
Output is correct |
15 |
Correct |
24 ms |
768 KB |
Output is correct |
16 |
Correct |
32 ms |
768 KB |
Output is correct |
17 |
Correct |
74 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
600 ms |
684 KB |
Output is correct |
2 |
Correct |
436 ms |
684 KB |
Output is correct |
3 |
Correct |
373 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
381 ms |
684 KB |
Output is correct |
8 |
Correct |
542 ms |
796 KB |
Output is correct |
9 |
Correct |
424 ms |
792 KB |
Output is correct |
10 |
Correct |
344 ms |
792 KB |
Output is correct |
11 |
Correct |
4 ms |
768 KB |
Output is correct |
12 |
Correct |
3 ms |
764 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
2 ms |
764 KB |
Output is correct |
15 |
Correct |
1 ms |
768 KB |
Output is correct |
16 |
Correct |
296 ms |
684 KB |
Output is correct |
17 |
Correct |
289 ms |
684 KB |
Output is correct |
18 |
Correct |
282 ms |
684 KB |
Output is correct |
19 |
Correct |
290 ms |
796 KB |
Output is correct |
20 |
Correct |
313 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
326 ms |
940 KB |
Output is correct |
2 |
Correct |
334 ms |
684 KB |
Output is correct |
3 |
Correct |
596 ms |
684 KB |
Output is correct |
4 |
Correct |
426 ms |
684 KB |
Output is correct |
5 |
Correct |
366 ms |
684 KB |
Output is correct |
6 |
Correct |
285 ms |
940 KB |
Output is correct |
7 |
Correct |
316 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
764 KB |
Output is correct |
9 |
Correct |
2 ms |
776 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
302 ms |
876 KB |
Output is correct |
12 |
Correct |
339 ms |
684 KB |
Output is correct |
13 |
Correct |
588 ms |
684 KB |
Output is correct |
14 |
Correct |
440 ms |
684 KB |
Output is correct |
15 |
Correct |
359 ms |
684 KB |
Output is correct |
16 |
Correct |
274 ms |
684 KB |
Output is correct |
17 |
Correct |
345 ms |
684 KB |
Output is correct |
18 |
Correct |
270 ms |
692 KB |
Output is correct |
19 |
Correct |
275 ms |
1188 KB |
Output is correct |
20 |
Correct |
243 ms |
684 KB |
Output is correct |
21 |
Correct |
23 ms |
768 KB |
Output is correct |
22 |
Correct |
33 ms |
768 KB |
Output is correct |
23 |
Correct |
55 ms |
768 KB |
Output is correct |
24 |
Correct |
2 ms |
772 KB |
Output is correct |
25 |
Correct |
2 ms |
780 KB |
Output is correct |
26 |
Correct |
2 ms |
808 KB |
Output is correct |
27 |
Correct |
1 ms |
768 KB |
Output is correct |
28 |
Correct |
0 ms |
768 KB |
Output is correct |
29 |
Correct |
355 ms |
792 KB |
Output is correct |
30 |
Correct |
330 ms |
684 KB |
Output is correct |
31 |
Correct |
297 ms |
684 KB |
Output is correct |
32 |
Correct |
358 ms |
684 KB |
Output is correct |
33 |
Correct |
298 ms |
940 KB |
Output is correct |
34 |
Correct |
188 ms |
684 KB |
Output is correct |
35 |
Correct |
267 ms |
940 KB |
Output is correct |
36 |
Correct |
242 ms |
1304 KB |
Output is correct |
37 |
Correct |
224 ms |
900 KB |
Output is correct |
38 |
Correct |
229 ms |
804 KB |
Output is correct |
39 |
Correct |
224 ms |
800 KB |
Output is correct |
40 |
Correct |
230 ms |
932 KB |
Output is correct |
41 |
Correct |
265 ms |
1044 KB |
Output is correct |
42 |
Correct |
28 ms |
744 KB |
Output is correct |
43 |
Correct |
55 ms |
864 KB |
Output is correct |
44 |
Correct |
79 ms |
792 KB |
Output is correct |
45 |
Correct |
76 ms |
920 KB |
Output is correct |
46 |
Correct |
151 ms |
684 KB |
Output is correct |
47 |
Correct |
173 ms |
792 KB |
Output is correct |
48 |
Correct |
39 ms |
1068 KB |
Output is correct |
49 |
Correct |
28 ms |
1304 KB |
Output is correct |