#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int mn = 0;
map<int,bool> mp;
int dfs(int node, int p, vector<vector<int>> &g, vector<int> &sub_tree){
for(auto &x: g[node]){
if(x == p) continue;
sub_tree[node]+=dfs(x,node,g,sub_tree);
}
return sub_tree[node]=sub_tree[node]+1;
}
void calc_labels(int node, int p, int t, vector<vector<int>> &g, vector<int> &sub_tree, vector<int> &labels){
if(!t){
while(mp[mn]) mn++;
mp[mn] = 1;
labels[node] = mn;
while(mp[mn]) mn++;
}
int turno = t^1;
for(auto &x: g[node]){
if(x == p) continue;
calc_labels(x,node,turno,g,sub_tree,labels);
}
if(t){
while(mp[mn]) mn++;
mp[mn] = 1;
labels[node] = mn;
while(mp[mn]) mn++;
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
vector<int> sub_tree(n,0);
vector<vector<int>> g(n);
vector<int> labels(n);
for(int i = 0; i<n-1; i++){
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
}
dfs(0,-1,g,sub_tree);
calc_labels(0,-1,1,g,sub_tree,labels);
mn = 0;
mp.clear();
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c[0]>s){
int l = s;
for(int i = 0; i<c.size()-1; i++){
if(t>=l and t<=c[i]){
return c[i];
}
else l = c[i]+1;
}
return c.back();
}
else{
int r = s;
for(int i = c.size()-1; i; i--){
if(t>=c[i] and t<=r) return c[i];
else r = c[i]-1;
}
return c[0];
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i = 0; i<c.size()-1; i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
940 KB |
Output is correct |
2 |
Correct |
303 ms |
940 KB |
Output is correct |
3 |
Correct |
625 ms |
684 KB |
Output is correct |
4 |
Correct |
447 ms |
684 KB |
Output is correct |
5 |
Correct |
424 ms |
684 KB |
Output is correct |
6 |
Correct |
305 ms |
940 KB |
Output is correct |
7 |
Correct |
314 ms |
940 KB |
Output is correct |
8 |
Correct |
2 ms |
776 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
292 ms |
684 KB |
Output is correct |
2 |
Correct |
378 ms |
688 KB |
Output is correct |
3 |
Correct |
626 ms |
940 KB |
Output is correct |
4 |
Correct |
453 ms |
684 KB |
Output is correct |
5 |
Correct |
427 ms |
684 KB |
Output is correct |
6 |
Correct |
319 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
399 ms |
940 KB |
Output is correct |
2 |
Correct |
329 ms |
940 KB |
Output is correct |
3 |
Correct |
584 ms |
684 KB |
Output is correct |
4 |
Correct |
480 ms |
684 KB |
Output is correct |
5 |
Correct |
380 ms |
684 KB |
Output is correct |
6 |
Correct |
322 ms |
940 KB |
Output is correct |
7 |
Correct |
342 ms |
940 KB |
Output is correct |
8 |
Correct |
1 ms |
776 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
11 |
Correct |
395 ms |
684 KB |
Output is correct |
12 |
Correct |
309 ms |
1272 KB |
Output is correct |
13 |
Correct |
287 ms |
1020 KB |
Output is correct |
14 |
Correct |
327 ms |
704 KB |
Output is correct |
15 |
Correct |
32 ms |
768 KB |
Output is correct |
16 |
Correct |
36 ms |
764 KB |
Output is correct |
17 |
Correct |
72 ms |
712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
618 ms |
684 KB |
Output is correct |
2 |
Correct |
478 ms |
684 KB |
Output is correct |
3 |
Correct |
414 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
0 ms |
776 KB |
Output is correct |
7 |
Correct |
412 ms |
772 KB |
Output is correct |
8 |
Correct |
583 ms |
940 KB |
Output is correct |
9 |
Correct |
455 ms |
684 KB |
Output is correct |
10 |
Correct |
378 ms |
684 KB |
Output is correct |
11 |
Correct |
3 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
764 KB |
Output is correct |
13 |
Correct |
2 ms |
768 KB |
Output is correct |
14 |
Correct |
3 ms |
768 KB |
Output is correct |
15 |
Correct |
1 ms |
768 KB |
Output is correct |
16 |
Correct |
376 ms |
684 KB |
Output is correct |
17 |
Correct |
303 ms |
684 KB |
Output is correct |
18 |
Correct |
337 ms |
684 KB |
Output is correct |
19 |
Correct |
381 ms |
684 KB |
Output is correct |
20 |
Correct |
345 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
369 ms |
940 KB |
Output is correct |
2 |
Correct |
310 ms |
940 KB |
Output is correct |
3 |
Correct |
595 ms |
684 KB |
Output is correct |
4 |
Correct |
504 ms |
684 KB |
Output is correct |
5 |
Correct |
399 ms |
688 KB |
Output is correct |
6 |
Correct |
294 ms |
940 KB |
Output is correct |
7 |
Correct |
302 ms |
940 KB |
Output is correct |
8 |
Correct |
1 ms |
764 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
11 |
Correct |
301 ms |
776 KB |
Output is correct |
12 |
Correct |
387 ms |
696 KB |
Output is correct |
13 |
Correct |
646 ms |
684 KB |
Output is correct |
14 |
Correct |
424 ms |
684 KB |
Output is correct |
15 |
Correct |
391 ms |
684 KB |
Output is correct |
16 |
Correct |
286 ms |
684 KB |
Output is correct |
17 |
Correct |
382 ms |
684 KB |
Output is correct |
18 |
Correct |
322 ms |
1188 KB |
Output is correct |
19 |
Correct |
339 ms |
1188 KB |
Output is correct |
20 |
Correct |
288 ms |
684 KB |
Output is correct |
21 |
Correct |
30 ms |
764 KB |
Output is correct |
22 |
Correct |
36 ms |
776 KB |
Output is correct |
23 |
Correct |
59 ms |
684 KB |
Output is correct |
24 |
Correct |
3 ms |
764 KB |
Output is correct |
25 |
Correct |
2 ms |
776 KB |
Output is correct |
26 |
Correct |
2 ms |
768 KB |
Output is correct |
27 |
Correct |
1 ms |
768 KB |
Output is correct |
28 |
Correct |
2 ms |
776 KB |
Output is correct |
29 |
Correct |
393 ms |
684 KB |
Output is correct |
30 |
Correct |
380 ms |
684 KB |
Output is correct |
31 |
Correct |
334 ms |
684 KB |
Output is correct |
32 |
Correct |
364 ms |
684 KB |
Output is correct |
33 |
Correct |
317 ms |
684 KB |
Output is correct |
34 |
Correct |
215 ms |
940 KB |
Output is correct |
35 |
Correct |
314 ms |
1196 KB |
Output is correct |
36 |
Correct |
301 ms |
1012 KB |
Output is correct |
37 |
Correct |
299 ms |
764 KB |
Output is correct |
38 |
Correct |
330 ms |
772 KB |
Output is correct |
39 |
Correct |
279 ms |
1036 KB |
Output is correct |
40 |
Correct |
311 ms |
1188 KB |
Output is correct |
41 |
Correct |
317 ms |
940 KB |
Output is correct |
42 |
Correct |
40 ms |
768 KB |
Output is correct |
43 |
Correct |
60 ms |
684 KB |
Output is correct |
44 |
Correct |
73 ms |
748 KB |
Output is correct |
45 |
Correct |
99 ms |
684 KB |
Output is correct |
46 |
Correct |
221 ms |
684 KB |
Output is correct |
47 |
Correct |
200 ms |
980 KB |
Output is correct |
48 |
Correct |
27 ms |
760 KB |
Output is correct |
49 |
Correct |
37 ms |
972 KB |
Output is correct |