#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define N 1000
vector<int> adj[N];
int tin[N];
int tout[N];
int dep[N];
int timer = 0;
void dfs(int v,int par){
tin[v] = timer++;
for(auto u:adj[v]){
if(u == par)continue;
dep[u] = dep[v]+1;
dfs(u,v);
}
tout[v] = timer-1;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
timer = 0;
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]);
}
dfs(0,-1);
vector<int> labels(n);
vector<pair<int,pair<int,int>>> ord;
for (int i = 0; i < n; i++) {
if(dep[i] & 1){
ord.push_back({tin[i],{-dep[i],i}});
}
else{
ord.push_back({tout[i],{-dep[i],i}});
}
}
sort(ord.begin(),ord.end());
for(int i = 0;i<n;i++){
labels[ord[i].second.second] = i;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
int sz = c.size();
sort(c.begin(),c.end());
for(auto u:c){
if(u == t)
return u;
}
if(c[0] > s){
int last = s + 1;
for(int i = 0;i<sz-1;i++){
if(last <= t && t <= c[i]){
return c[i];
}
last = c[i] + 1;
}
return c[sz-1];
}
else{
reverse(c.begin(),c.end());
int last = s - 1;
for(int i = 0;i<sz-1;i++){
if(c[i] <= t && t <= last){
return c[i];
}
last = c[i] - 1;
}
return c[sz-1];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
556 ms |
660 KB |
Output is correct |
2 |
Correct |
424 ms |
660 KB |
Output is correct |
3 |
Correct |
851 ms |
520 KB |
Output is correct |
4 |
Correct |
627 ms |
436 KB |
Output is correct |
5 |
Correct |
495 ms |
532 KB |
Output is correct |
6 |
Correct |
453 ms |
672 KB |
Output is correct |
7 |
Correct |
426 ms |
548 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
5 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
427 ms |
596 KB |
Output is correct |
2 |
Correct |
548 ms |
548 KB |
Output is correct |
3 |
Correct |
725 ms |
528 KB |
Output is correct |
4 |
Correct |
625 ms |
544 KB |
Output is correct |
5 |
Correct |
547 ms |
528 KB |
Output is correct |
6 |
Correct |
459 ms |
536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
512 ms |
664 KB |
Output is correct |
2 |
Correct |
410 ms |
672 KB |
Output is correct |
3 |
Correct |
892 ms |
528 KB |
Output is correct |
4 |
Correct |
660 ms |
536 KB |
Output is correct |
5 |
Correct |
596 ms |
416 KB |
Output is correct |
6 |
Correct |
434 ms |
652 KB |
Output is correct |
7 |
Correct |
416 ms |
656 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
6 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
534 ms |
548 KB |
Output is correct |
12 |
Correct |
471 ms |
736 KB |
Output is correct |
13 |
Correct |
394 ms |
760 KB |
Output is correct |
14 |
Correct |
366 ms |
532 KB |
Output is correct |
15 |
Correct |
53 ms |
620 KB |
Output is correct |
16 |
Correct |
105 ms |
544 KB |
Output is correct |
17 |
Correct |
89 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
820 ms |
512 KB |
Output is correct |
2 |
Correct |
768 ms |
512 KB |
Output is correct |
3 |
Correct |
702 ms |
528 KB |
Output is correct |
4 |
Correct |
3 ms |
620 KB |
Output is correct |
5 |
Correct |
3 ms |
620 KB |
Output is correct |
6 |
Correct |
0 ms |
620 KB |
Output is correct |
7 |
Correct |
599 ms |
548 KB |
Output is correct |
8 |
Correct |
1075 ms |
512 KB |
Output is correct |
9 |
Correct |
791 ms |
532 KB |
Output is correct |
10 |
Correct |
598 ms |
556 KB |
Output is correct |
11 |
Correct |
5 ms |
632 KB |
Output is correct |
12 |
Correct |
9 ms |
492 KB |
Output is correct |
13 |
Correct |
4 ms |
624 KB |
Output is correct |
14 |
Correct |
3 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
593 ms |
532 KB |
Output is correct |
17 |
Correct |
533 ms |
532 KB |
Output is correct |
18 |
Correct |
575 ms |
548 KB |
Output is correct |
19 |
Correct |
510 ms |
532 KB |
Output is correct |
20 |
Correct |
467 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
445 ms |
796 KB |
Output is correct |
2 |
Correct |
385 ms |
672 KB |
Output is correct |
3 |
Correct |
920 ms |
508 KB |
Output is correct |
4 |
Correct |
640 ms |
576 KB |
Output is correct |
5 |
Correct |
482 ms |
532 KB |
Output is correct |
6 |
Correct |
370 ms |
656 KB |
Output is correct |
7 |
Correct |
519 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
4 ms |
628 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
458 ms |
548 KB |
Output is correct |
12 |
Correct |
527 ms |
548 KB |
Output is correct |
13 |
Correct |
880 ms |
416 KB |
Output is correct |
14 |
Correct |
590 ms |
536 KB |
Output is correct |
15 |
Correct |
550 ms |
420 KB |
Output is correct |
16 |
Correct |
359 ms |
544 KB |
Output is correct |
17 |
Correct |
635 ms |
536 KB |
Output is correct |
18 |
Correct |
412 ms |
648 KB |
Output is correct |
19 |
Correct |
476 ms |
776 KB |
Output is correct |
20 |
Correct |
331 ms |
524 KB |
Output is correct |
21 |
Correct |
48 ms |
544 KB |
Output is correct |
22 |
Correct |
59 ms |
544 KB |
Output is correct |
23 |
Correct |
103 ms |
548 KB |
Output is correct |
24 |
Correct |
6 ms |
624 KB |
Output is correct |
25 |
Correct |
6 ms |
492 KB |
Output is correct |
26 |
Correct |
4 ms |
632 KB |
Output is correct |
27 |
Correct |
4 ms |
496 KB |
Output is correct |
28 |
Correct |
1 ms |
620 KB |
Output is correct |
29 |
Correct |
485 ms |
528 KB |
Output is correct |
30 |
Correct |
494 ms |
548 KB |
Output is correct |
31 |
Correct |
475 ms |
420 KB |
Output is correct |
32 |
Correct |
527 ms |
588 KB |
Output is correct |
33 |
Correct |
500 ms |
548 KB |
Output is correct |
34 |
Correct |
273 ms |
664 KB |
Output is correct |
35 |
Correct |
380 ms |
620 KB |
Output is correct |
36 |
Correct |
445 ms |
768 KB |
Output is correct |
37 |
Correct |
446 ms |
524 KB |
Output is correct |
38 |
Correct |
453 ms |
648 KB |
Output is correct |
39 |
Correct |
406 ms |
656 KB |
Output is correct |
40 |
Correct |
409 ms |
772 KB |
Output is correct |
41 |
Correct |
486 ms |
640 KB |
Output is correct |
42 |
Correct |
54 ms |
672 KB |
Output is correct |
43 |
Correct |
137 ms |
672 KB |
Output is correct |
44 |
Correct |
124 ms |
548 KB |
Output is correct |
45 |
Correct |
201 ms |
536 KB |
Output is correct |
46 |
Correct |
323 ms |
544 KB |
Output is correct |
47 |
Correct |
242 ms |
660 KB |
Output is correct |
48 |
Correct |
59 ms |
836 KB |
Output is correct |
49 |
Correct |
56 ms |
820 KB |
Output is correct |