#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN=1000;
int n, tin[mxN], tout[mxN], t, d[mxN];
vector<int> adj[mxN];
void dfs(int u=0, int p=-1) {
tin[u]=t++;
for (int v : adj[u])
if (v!=p) {
d[v]=d[u]+1;
dfs(v, u);
}
tout[u]=t++;
}
vector<int> label(int _n, int _k, vector<int> u, vector<int> v) {
n=_n;
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();
vector<int> inds(n), labels(n);
iota(inds.begin(), inds.end(), 0);
sort(inds.begin(), inds.end(), [](int a, int b) { return (d[a]%2?tout[a]:tin[a])<(d[b]%2?tout[b]:tin[b]); });
for (int i=0; i<n; ++i)
labels[inds[i]]=i;
/*for (int i : labels)
cout << i << " ";
cout << endl;*/
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if (c.back()>s) { // s is tin[s]
if (!s||s<=t&&t<=c.end()[-2]) { // t is in subtree of s
for (int i=0; i+(s>0)<c.size(); ++i)
if (t<=c[i])
return c[i];
assert(0);
} else
return c.back();
} else {
if (c.size()>1&&c[1]<=t&&t<=s) { // again in subtree
for (int i=c.size()-1; i; --i)
if (t>=c[i])
return c[i];
assert(0);
} else
return c[0];
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:41:15: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
41 | if (!s||s<=t&&t<=c.end()[-2]) { // t is in subtree of s
stations.cpp:42:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i=0; i+(s>0)<c.size(); ++i)
| ~~~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
587 ms |
516 KB |
Output is correct |
2 |
Correct |
445 ms |
644 KB |
Output is correct |
3 |
Correct |
786 ms |
524 KB |
Output is correct |
4 |
Correct |
674 ms |
528 KB |
Output is correct |
5 |
Correct |
519 ms |
416 KB |
Output is correct |
6 |
Correct |
555 ms |
532 KB |
Output is correct |
7 |
Correct |
366 ms |
508 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
405 ms |
544 KB |
Output is correct |
2 |
Correct |
480 ms |
560 KB |
Output is correct |
3 |
Correct |
852 ms |
532 KB |
Output is correct |
4 |
Correct |
654 ms |
628 KB |
Output is correct |
5 |
Correct |
743 ms |
544 KB |
Output is correct |
6 |
Correct |
386 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
638 ms |
784 KB |
Output is correct |
2 |
Correct |
448 ms |
644 KB |
Output is correct |
3 |
Correct |
855 ms |
576 KB |
Output is correct |
4 |
Correct |
649 ms |
532 KB |
Output is correct |
5 |
Correct |
498 ms |
512 KB |
Output is correct |
6 |
Correct |
337 ms |
640 KB |
Output is correct |
7 |
Correct |
447 ms |
528 KB |
Output is correct |
8 |
Correct |
1 ms |
488 KB |
Output is correct |
9 |
Correct |
3 ms |
628 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
11 |
Correct |
588 ms |
528 KB |
Output is correct |
12 |
Correct |
435 ms |
784 KB |
Output is correct |
13 |
Correct |
441 ms |
808 KB |
Output is correct |
14 |
Correct |
455 ms |
660 KB |
Output is correct |
15 |
Correct |
51 ms |
560 KB |
Output is correct |
16 |
Correct |
67 ms |
584 KB |
Output is correct |
17 |
Correct |
117 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
750 ms |
532 KB |
Output is correct |
2 |
Correct |
654 ms |
524 KB |
Output is correct |
3 |
Correct |
583 ms |
660 KB |
Output is correct |
4 |
Correct |
2 ms |
620 KB |
Output is correct |
5 |
Correct |
4 ms |
492 KB |
Output is correct |
6 |
Correct |
0 ms |
500 KB |
Output is correct |
7 |
Correct |
582 ms |
416 KB |
Output is correct |
8 |
Correct |
667 ms |
596 KB |
Output is correct |
9 |
Correct |
589 ms |
548 KB |
Output is correct |
10 |
Correct |
530 ms |
544 KB |
Output is correct |
11 |
Correct |
4 ms |
488 KB |
Output is correct |
12 |
Correct |
5 ms |
628 KB |
Output is correct |
13 |
Correct |
5 ms |
620 KB |
Output is correct |
14 |
Correct |
3 ms |
488 KB |
Output is correct |
15 |
Correct |
1 ms |
628 KB |
Output is correct |
16 |
Correct |
511 ms |
416 KB |
Output is correct |
17 |
Correct |
476 ms |
416 KB |
Output is correct |
18 |
Correct |
360 ms |
544 KB |
Output is correct |
19 |
Correct |
445 ms |
548 KB |
Output is correct |
20 |
Correct |
368 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
440 ms |
656 KB |
Output is correct |
2 |
Correct |
410 ms |
656 KB |
Output is correct |
3 |
Correct |
763 ms |
516 KB |
Output is correct |
4 |
Correct |
651 ms |
524 KB |
Output is correct |
5 |
Correct |
564 ms |
528 KB |
Output is correct |
6 |
Correct |
452 ms |
656 KB |
Output is correct |
7 |
Correct |
420 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
4 ms |
624 KB |
Output is correct |
10 |
Correct |
0 ms |
620 KB |
Output is correct |
11 |
Correct |
446 ms |
588 KB |
Output is correct |
12 |
Correct |
514 ms |
548 KB |
Output is correct |
13 |
Correct |
786 ms |
524 KB |
Output is correct |
14 |
Correct |
588 ms |
536 KB |
Output is correct |
15 |
Correct |
531 ms |
528 KB |
Output is correct |
16 |
Correct |
446 ms |
528 KB |
Output is correct |
17 |
Correct |
608 ms |
528 KB |
Output is correct |
18 |
Correct |
426 ms |
632 KB |
Output is correct |
19 |
Correct |
488 ms |
784 KB |
Output is correct |
20 |
Correct |
430 ms |
520 KB |
Output is correct |
21 |
Correct |
57 ms |
620 KB |
Output is correct |
22 |
Correct |
60 ms |
736 KB |
Output is correct |
23 |
Correct |
107 ms |
672 KB |
Output is correct |
24 |
Correct |
4 ms |
620 KB |
Output is correct |
25 |
Correct |
5 ms |
620 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
628 KB |
Output is correct |
28 |
Correct |
1 ms |
620 KB |
Output is correct |
29 |
Correct |
527 ms |
544 KB |
Output is correct |
30 |
Correct |
455 ms |
416 KB |
Output is correct |
31 |
Correct |
473 ms |
528 KB |
Output is correct |
32 |
Correct |
486 ms |
420 KB |
Output is correct |
33 |
Correct |
528 ms |
528 KB |
Output is correct |
34 |
Correct |
248 ms |
524 KB |
Output is correct |
35 |
Correct |
373 ms |
544 KB |
Output is correct |
36 |
Correct |
454 ms |
748 KB |
Output is correct |
37 |
Correct |
481 ms |
604 KB |
Output is correct |
38 |
Correct |
490 ms |
756 KB |
Output is correct |
39 |
Correct |
483 ms |
656 KB |
Output is correct |
40 |
Correct |
484 ms |
640 KB |
Output is correct |
41 |
Correct |
477 ms |
644 KB |
Output is correct |
42 |
Correct |
64 ms |
676 KB |
Output is correct |
43 |
Correct |
104 ms |
696 KB |
Output is correct |
44 |
Correct |
105 ms |
544 KB |
Output is correct |
45 |
Correct |
173 ms |
536 KB |
Output is correct |
46 |
Correct |
324 ms |
608 KB |
Output is correct |
47 |
Correct |
317 ms |
528 KB |
Output is correct |
48 |
Correct |
61 ms |
712 KB |
Output is correct |
49 |
Correct |
61 ms |
900 KB |
Output is correct |