#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
vector<int> g[N];
int tin[N], tout[N], dp[N];
int tim=0, tim2=0;
void dfs(int at, int p) {
if(dp[at])
tin[at]=tim++;
for(int to:g[at])
{
if(to==p)continue;
dp[to] = dp[at]^1;
dfs(to, at);
}
if(!dp[at])
tout[at]=tim++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
for(int i = 0;i<=n;i++)g[i].clear();
tim=0;
for(int i = 0;i<n-1;i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs(0,0);
for (int i = 0; i < n; i++) {
if(dp[i])labels[i] = tin[i];
else labels[i] = tout[i];
// cout << i << " " << labels[i] << endl;
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
vector<int> kk = c;
if(c.size()==1)return c[0];
sort(kk.begin(), kk.end());
if(kk[0] >= s) {
if(t <= s)return kk.back();
for(int i = 0;i<kk.size();i++) {
if(kk[i] >= t)return kk[i];
}
return kk.back();
}
else if(kk.back() <= s) {
if(t >= s)return kk[0];
for(int i = kk.size()-1;i>=0;i--) {
if(kk[i] <= t) {
return kk[i];
}
}
return kk[0];
}
return 0;
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i = 0;i<kk.size();i++) {
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
329 ms |
688 KB |
Output is correct |
2 |
Correct |
301 ms |
1424 KB |
Output is correct |
3 |
Correct |
553 ms |
800 KB |
Output is correct |
4 |
Correct |
358 ms |
792 KB |
Output is correct |
5 |
Correct |
356 ms |
684 KB |
Output is correct |
6 |
Correct |
290 ms |
684 KB |
Output is correct |
7 |
Correct |
265 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
284 ms |
684 KB |
Output is correct |
2 |
Correct |
323 ms |
684 KB |
Output is correct |
3 |
Correct |
522 ms |
684 KB |
Output is correct |
4 |
Correct |
354 ms |
684 KB |
Output is correct |
5 |
Correct |
345 ms |
684 KB |
Output is correct |
6 |
Correct |
232 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
229 ms |
684 KB |
Output is correct |
2 |
Correct |
255 ms |
684 KB |
Output is correct |
3 |
Correct |
532 ms |
684 KB |
Output is correct |
4 |
Correct |
362 ms |
684 KB |
Output is correct |
5 |
Correct |
351 ms |
712 KB |
Output is correct |
6 |
Correct |
256 ms |
684 KB |
Output is correct |
7 |
Correct |
271 ms |
684 KB |
Output is correct |
8 |
Correct |
0 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
772 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
347 ms |
812 KB |
Output is correct |
12 |
Correct |
246 ms |
1044 KB |
Output is correct |
13 |
Correct |
281 ms |
788 KB |
Output is correct |
14 |
Correct |
277 ms |
684 KB |
Output is correct |
15 |
Correct |
23 ms |
768 KB |
Output is correct |
16 |
Correct |
26 ms |
768 KB |
Output is correct |
17 |
Correct |
40 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
482 ms |
684 KB |
Output is correct |
2 |
Correct |
392 ms |
684 KB |
Output is correct |
3 |
Correct |
354 ms |
684 KB |
Output is correct |
4 |
Correct |
0 ms |
776 KB |
Output is correct |
5 |
Correct |
1 ms |
776 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
342 ms |
800 KB |
Output is correct |
8 |
Correct |
512 ms |
684 KB |
Output is correct |
9 |
Correct |
376 ms |
684 KB |
Output is correct |
10 |
Correct |
352 ms |
684 KB |
Output is correct |
11 |
Correct |
3 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
772 KB |
Output is correct |
14 |
Correct |
1 ms |
764 KB |
Output is correct |
15 |
Correct |
0 ms |
772 KB |
Output is correct |
16 |
Correct |
290 ms |
684 KB |
Output is correct |
17 |
Correct |
294 ms |
684 KB |
Output is correct |
18 |
Correct |
270 ms |
684 KB |
Output is correct |
19 |
Correct |
295 ms |
684 KB |
Output is correct |
20 |
Correct |
277 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
274 ms |
684 KB |
Output is correct |
2 |
Correct |
239 ms |
684 KB |
Output is correct |
3 |
Correct |
502 ms |
684 KB |
Output is correct |
4 |
Correct |
407 ms |
684 KB |
Output is correct |
5 |
Correct |
318 ms |
688 KB |
Output is correct |
6 |
Correct |
244 ms |
688 KB |
Output is correct |
7 |
Correct |
235 ms |
684 KB |
Output is correct |
8 |
Correct |
0 ms |
764 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
262 ms |
684 KB |
Output is correct |
12 |
Correct |
339 ms |
684 KB |
Output is correct |
13 |
Correct |
488 ms |
684 KB |
Output is correct |
14 |
Correct |
394 ms |
684 KB |
Output is correct |
15 |
Correct |
339 ms |
684 KB |
Output is correct |
16 |
Correct |
229 ms |
684 KB |
Output is correct |
17 |
Correct |
318 ms |
684 KB |
Output is correct |
18 |
Correct |
230 ms |
936 KB |
Output is correct |
19 |
Correct |
272 ms |
1188 KB |
Output is correct |
20 |
Correct |
233 ms |
684 KB |
Output is correct |
21 |
Correct |
24 ms |
768 KB |
Output is correct |
22 |
Correct |
25 ms |
764 KB |
Output is correct |
23 |
Correct |
54 ms |
716 KB |
Output is correct |
24 |
Correct |
3 ms |
768 KB |
Output is correct |
25 |
Correct |
3 ms |
768 KB |
Output is correct |
26 |
Correct |
2 ms |
764 KB |
Output is correct |
27 |
Correct |
2 ms |
768 KB |
Output is correct |
28 |
Correct |
0 ms |
764 KB |
Output is correct |
29 |
Correct |
290 ms |
684 KB |
Output is correct |
30 |
Correct |
292 ms |
684 KB |
Output is correct |
31 |
Correct |
285 ms |
684 KB |
Output is correct |
32 |
Correct |
296 ms |
684 KB |
Output is correct |
33 |
Correct |
307 ms |
684 KB |
Output is correct |
34 |
Correct |
173 ms |
716 KB |
Output is correct |
35 |
Correct |
225 ms |
820 KB |
Output is correct |
36 |
Correct |
261 ms |
932 KB |
Output is correct |
37 |
Correct |
247 ms |
812 KB |
Output is correct |
38 |
Correct |
258 ms |
684 KB |
Output is correct |
39 |
Correct |
264 ms |
940 KB |
Output is correct |
40 |
Correct |
261 ms |
804 KB |
Output is correct |
41 |
Correct |
259 ms |
800 KB |
Output is correct |
42 |
Correct |
36 ms |
1016 KB |
Output is correct |
43 |
Correct |
69 ms |
880 KB |
Output is correct |
44 |
Correct |
73 ms |
732 KB |
Output is correct |
45 |
Correct |
77 ms |
972 KB |
Output is correct |
46 |
Correct |
180 ms |
684 KB |
Output is correct |
47 |
Correct |
194 ms |
700 KB |
Output is correct |
48 |
Correct |
33 ms |
768 KB |
Output is correct |
49 |
Correct |
24 ms |
776 KB |
Output is correct |