# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1050146 |
2024-08-09T07:41:55 Z |
idas |
Stations (IOI20_stations) |
C++17 |
|
523 ms |
1048 KB |
#include "stations.h"
#include "bits/stdc++.h"
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) ((int)((x).size()))
#define pb push_back
using namespace std;
typedef vector<int> vi;
const int N=1e3+10;
int in[N], dp[N], id;
vi ad[N];
void dfs(int u, int pst=-1) {
if(dp[u]&1^1) in[u]=id++;
for(auto it : ad[u]) {
if(it==pst) continue;
dp[it]=dp[u]+1;
dfs(it, u);
}
if(dp[u]&1) in[u]=id++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
FOR(i, 0, n) ad[i].clear(), dp[i]=in[i]=0;
FOR(i, 0, n-1) {
ad[u[i]].pb(v[i]), ad[v[i]].pb(u[i]);
}
id=0; dfs(0);
vi b(n); FOR(i, 0, n) b[i]=in[i];
return b;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s<c[0]) {
if(t<s) return c[sz(c)-1];
FOR(i, 0, sz(c)) {
if(t<=c[i]) return c[i];
}
return c[sz(c)-1];
}
else {
if(t>s) return c[0];
for(int i=sz(c)-1; i>=0; i--) {
if(t>=c[i]) return c[i];
}
return c[0];
}
}
/*
2
5 10
0 1
1 2
1 3
2 4
2
2 0 1
1 3 3
5 10
0 1
1 2
2 3
3 4
1
4 0 2
*/
Compilation message
stations.cpp: In function 'void dfs(int, int)':
stations.cpp:15:10: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
15 | if(dp[u]&1^1) in[u]=id++;
| ~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
311 ms |
684 KB |
Output is correct |
2 |
Correct |
230 ms |
684 KB |
Output is correct |
3 |
Correct |
513 ms |
684 KB |
Output is correct |
4 |
Correct |
387 ms |
684 KB |
Output is correct |
5 |
Correct |
304 ms |
684 KB |
Output is correct |
6 |
Correct |
282 ms |
684 KB |
Output is correct |
7 |
Correct |
266 ms |
684 KB |
Output is correct |
8 |
Correct |
0 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
776 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
716 KB |
Output is correct |
2 |
Correct |
295 ms |
708 KB |
Output is correct |
3 |
Correct |
523 ms |
684 KB |
Output is correct |
4 |
Correct |
361 ms |
784 KB |
Output is correct |
5 |
Correct |
324 ms |
684 KB |
Output is correct |
6 |
Correct |
296 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
328 ms |
684 KB |
Output is correct |
2 |
Correct |
238 ms |
684 KB |
Output is correct |
3 |
Correct |
520 ms |
684 KB |
Output is correct |
4 |
Correct |
399 ms |
684 KB |
Output is correct |
5 |
Correct |
326 ms |
684 KB |
Output is correct |
6 |
Correct |
246 ms |
684 KB |
Output is correct |
7 |
Correct |
271 ms |
684 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 |
772 KB |
Output is correct |
11 |
Correct |
322 ms |
800 KB |
Output is correct |
12 |
Correct |
270 ms |
796 KB |
Output is correct |
13 |
Correct |
277 ms |
936 KB |
Output is correct |
14 |
Correct |
235 ms |
684 KB |
Output is correct |
15 |
Correct |
24 ms |
768 KB |
Output is correct |
16 |
Correct |
28 ms |
768 KB |
Output is correct |
17 |
Correct |
45 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
523 ms |
684 KB |
Output is correct |
2 |
Correct |
367 ms |
684 KB |
Output is correct |
3 |
Correct |
333 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
776 KB |
Output is correct |
6 |
Correct |
0 ms |
776 KB |
Output is correct |
7 |
Correct |
353 ms |
800 KB |
Output is correct |
8 |
Correct |
516 ms |
684 KB |
Output is correct |
9 |
Correct |
390 ms |
684 KB |
Output is correct |
10 |
Correct |
309 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 |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
0 ms |
776 KB |
Output is correct |
16 |
Correct |
275 ms |
684 KB |
Output is correct |
17 |
Correct |
246 ms |
684 KB |
Output is correct |
18 |
Correct |
284 ms |
684 KB |
Output is correct |
19 |
Correct |
288 ms |
688 KB |
Output is correct |
20 |
Correct |
277 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
684 KB |
Output is correct |
2 |
Correct |
240 ms |
684 KB |
Output is correct |
3 |
Correct |
512 ms |
684 KB |
Output is correct |
4 |
Correct |
365 ms |
684 KB |
Output is correct |
5 |
Correct |
367 ms |
684 KB |
Output is correct |
6 |
Correct |
270 ms |
684 KB |
Output is correct |
7 |
Correct |
237 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 |
772 KB |
Output is correct |
11 |
Correct |
254 ms |
804 KB |
Output is correct |
12 |
Correct |
285 ms |
684 KB |
Output is correct |
13 |
Correct |
488 ms |
684 KB |
Output is correct |
14 |
Correct |
327 ms |
940 KB |
Output is correct |
15 |
Correct |
296 ms |
792 KB |
Output is correct |
16 |
Correct |
195 ms |
792 KB |
Output is correct |
17 |
Correct |
273 ms |
796 KB |
Output is correct |
18 |
Correct |
196 ms |
1048 KB |
Output is correct |
19 |
Correct |
215 ms |
784 KB |
Output is correct |
20 |
Correct |
212 ms |
684 KB |
Output is correct |
21 |
Correct |
24 ms |
768 KB |
Output is correct |
22 |
Correct |
37 ms |
768 KB |
Output is correct |
23 |
Correct |
61 ms |
716 KB |
Output is correct |
24 |
Correct |
2 ms |
768 KB |
Output is correct |
25 |
Correct |
3 ms |
776 KB |
Output is correct |
26 |
Correct |
1 ms |
768 KB |
Output is correct |
27 |
Correct |
1 ms |
768 KB |
Output is correct |
28 |
Correct |
0 ms |
768 KB |
Output is correct |
29 |
Correct |
244 ms |
940 KB |
Output is correct |
30 |
Correct |
263 ms |
684 KB |
Output is correct |
31 |
Correct |
229 ms |
684 KB |
Output is correct |
32 |
Correct |
264 ms |
684 KB |
Output is correct |
33 |
Correct |
254 ms |
796 KB |
Output is correct |
34 |
Correct |
162 ms |
684 KB |
Output is correct |
35 |
Correct |
250 ms |
920 KB |
Output is correct |
36 |
Correct |
273 ms |
1024 KB |
Output is correct |
37 |
Correct |
238 ms |
684 KB |
Output is correct |
38 |
Correct |
264 ms |
932 KB |
Output is correct |
39 |
Correct |
266 ms |
940 KB |
Output is correct |
40 |
Correct |
214 ms |
812 KB |
Output is correct |
41 |
Correct |
280 ms |
932 KB |
Output is correct |
42 |
Correct |
25 ms |
768 KB |
Output is correct |
43 |
Correct |
64 ms |
736 KB |
Output is correct |
44 |
Correct |
57 ms |
684 KB |
Output is correct |
45 |
Correct |
85 ms |
768 KB |
Output is correct |
46 |
Correct |
174 ms |
716 KB |
Output is correct |
47 |
Correct |
190 ms |
684 KB |
Output is correct |
48 |
Correct |
32 ms |
912 KB |
Output is correct |
49 |
Correct |
23 ms |
768 KB |
Output is correct |