#include "stations.h"
#include <vector>
#include <iostream>
using namespace std;
void traverse(int u, int p, vector<int> &sz, vector<vector<int>> &adj) {
sz[u] = 1;
for(int v : adj[u]) if(v != p) {
traverse(v, u, sz, adj);
sz[u] += sz[v];
}
}
/*
increment timer when going down if par == 0
increment timer when going up if par == 1
*/
void bipartite_labeling(int u, int p, int par, int &timer, vector<int> &sz,
vector<int> &labels, vector<vector<int>> &adj) {
labels[u] = par ? timer+sz[u]-1 : timer;
if(par == 0) timer++;
for(int v : adj[u]) if(v != p) {
bipartite_labeling(v, u, 1-par, timer, sz, labels, adj);
}
if(par == 1) timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n), sz(n);
vector<vector<int>> adj(n);
for(int i = 0; i < (int)u.size(); i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
traverse(0, -1, sz, adj);
bipartite_labeling(0, -1, 0, *new int{0}, sz, labels, adj);
return labels;
}
// c is sorted in ascending order
int find_next_station(int s, int t, vector<int> c) {
if(s == 0) {
// at root
for(int x : c) if(x >= t) return x;
}
else {
// 1 neighbor goes towards root, some down the tree
if(c.size() == 1) return c[0];
// determine which type of vertex is s
if(c.back() < s) {
// par = 1
// minimum label is toward the root
int up = c[0];
c.erase(c.begin());
if(t > s) return up;
int where = up;
for(int x : c) if(x <= t) where = x;
return where;
}
else {
// par = 0
// maximum label is toward the root
int up = c.back();
c.pop_back();
if(t < s) return up;
for(int x : c) if(x >= t) return x;
return up;
}
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
380 ms |
672 KB |
Output is correct |
2 |
Correct |
355 ms |
540 KB |
Output is correct |
3 |
Correct |
740 ms |
500 KB |
Output is correct |
4 |
Correct |
642 ms |
420 KB |
Output is correct |
5 |
Correct |
505 ms |
512 KB |
Output is correct |
6 |
Correct |
338 ms |
628 KB |
Output is correct |
7 |
Correct |
334 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
446 ms |
500 KB |
Output is correct |
2 |
Correct |
356 ms |
504 KB |
Output is correct |
3 |
Correct |
750 ms |
416 KB |
Output is correct |
4 |
Correct |
518 ms |
540 KB |
Output is correct |
5 |
Correct |
459 ms |
420 KB |
Output is correct |
6 |
Correct |
349 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
430 ms |
636 KB |
Output is correct |
2 |
Correct |
278 ms |
628 KB |
Output is correct |
3 |
Correct |
684 ms |
420 KB |
Output is correct |
4 |
Correct |
535 ms |
504 KB |
Output is correct |
5 |
Correct |
423 ms |
416 KB |
Output is correct |
6 |
Correct |
416 ms |
624 KB |
Output is correct |
7 |
Correct |
253 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
472 KB |
Output is correct |
11 |
Correct |
417 ms |
420 KB |
Output is correct |
12 |
Correct |
467 ms |
756 KB |
Output is correct |
13 |
Correct |
360 ms |
748 KB |
Output is correct |
14 |
Correct |
446 ms |
504 KB |
Output is correct |
15 |
Correct |
38 ms |
496 KB |
Output is correct |
16 |
Correct |
35 ms |
500 KB |
Output is correct |
17 |
Correct |
82 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
659 ms |
416 KB |
Output is correct |
2 |
Correct |
529 ms |
420 KB |
Output is correct |
3 |
Correct |
351 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
4 ms |
496 KB |
Output is correct |
6 |
Correct |
0 ms |
500 KB |
Output is correct |
7 |
Correct |
416 ms |
504 KB |
Output is correct |
8 |
Correct |
783 ms |
420 KB |
Output is correct |
9 |
Correct |
504 ms |
488 KB |
Output is correct |
10 |
Correct |
421 ms |
504 KB |
Output is correct |
11 |
Correct |
4 ms |
492 KB |
Output is correct |
12 |
Correct |
4 ms |
500 KB |
Output is correct |
13 |
Correct |
4 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
500 KB |
Output is correct |
16 |
Correct |
463 ms |
480 KB |
Output is correct |
17 |
Correct |
471 ms |
504 KB |
Output is correct |
18 |
Correct |
406 ms |
508 KB |
Output is correct |
19 |
Correct |
433 ms |
500 KB |
Output is correct |
20 |
Correct |
411 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
390 ms |
672 KB |
Output is correct |
2 |
Correct |
446 ms |
548 KB |
Output is correct |
3 |
Correct |
780 ms |
420 KB |
Output is correct |
4 |
Correct |
584 ms |
500 KB |
Output is correct |
5 |
Correct |
556 ms |
420 KB |
Output is correct |
6 |
Correct |
351 ms |
676 KB |
Output is correct |
7 |
Correct |
438 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
500 KB |
Output is correct |
9 |
Correct |
2 ms |
500 KB |
Output is correct |
10 |
Correct |
0 ms |
488 KB |
Output is correct |
11 |
Correct |
343 ms |
588 KB |
Output is correct |
12 |
Correct |
421 ms |
544 KB |
Output is correct |
13 |
Correct |
687 ms |
416 KB |
Output is correct |
14 |
Correct |
406 ms |
420 KB |
Output is correct |
15 |
Correct |
421 ms |
416 KB |
Output is correct |
16 |
Correct |
396 ms |
548 KB |
Output is correct |
17 |
Correct |
524 ms |
416 KB |
Output is correct |
18 |
Correct |
411 ms |
720 KB |
Output is correct |
19 |
Correct |
394 ms |
716 KB |
Output is correct |
20 |
Correct |
361 ms |
504 KB |
Output is correct |
21 |
Correct |
51 ms |
492 KB |
Output is correct |
22 |
Correct |
63 ms |
560 KB |
Output is correct |
23 |
Correct |
68 ms |
544 KB |
Output is correct |
24 |
Correct |
4 ms |
444 KB |
Output is correct |
25 |
Correct |
5 ms |
496 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
500 KB |
Output is correct |
28 |
Correct |
1 ms |
480 KB |
Output is correct |
29 |
Correct |
351 ms |
508 KB |
Output is correct |
30 |
Correct |
361 ms |
504 KB |
Output is correct |
31 |
Correct |
389 ms |
420 KB |
Output is correct |
32 |
Correct |
365 ms |
416 KB |
Output is correct |
33 |
Correct |
421 ms |
504 KB |
Output is correct |
34 |
Correct |
251 ms |
632 KB |
Output is correct |
35 |
Correct |
302 ms |
704 KB |
Output is correct |
36 |
Correct |
284 ms |
632 KB |
Output is correct |
37 |
Correct |
433 ms |
544 KB |
Output is correct |
38 |
Correct |
350 ms |
648 KB |
Output is correct |
39 |
Correct |
332 ms |
692 KB |
Output is correct |
40 |
Correct |
409 ms |
720 KB |
Output is correct |
41 |
Correct |
303 ms |
584 KB |
Output is correct |
42 |
Correct |
43 ms |
600 KB |
Output is correct |
43 |
Correct |
91 ms |
676 KB |
Output is correct |
44 |
Correct |
122 ms |
548 KB |
Output is correct |
45 |
Correct |
125 ms |
548 KB |
Output is correct |
46 |
Correct |
276 ms |
500 KB |
Output is correct |
47 |
Correct |
233 ms |
628 KB |
Output is correct |
48 |
Correct |
42 ms |
544 KB |
Output is correct |
49 |
Correct |
49 ms |
700 KB |
Output is correct |