#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int t, vis[1000];
vector<int> E[1000], labels;
// type 0: first, 1: last
void dfs(int u, int type)
{
vis[u] = 1;
if (type == 0)
labels[u] = t++;
for (auto v : E[u])
if (!vis[v])
dfs(v, type ^ 1);
if (type == 1)
labels[u] = t++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
t = 0;
for (int i = 0; i < n; i++)
E[i].clear(), vis[i] = 0;
for (int i = 0; i < n - 1; i++)
E[u[i]].emplace_back(v[i]), E[v[i]].emplace_back(u[i]);
labels.clear();
labels.resize(n);
dfs(0, 0);
return labels;
}
int find_next_station(int s, int t, vector<int> c)
{
int root = -1;
if (s < c[0])
{
if (s != 0)
{
root = c.back();
c.pop_back();
}
int pre = s;
for (int a : c)
{
if (pre <= t && t <= a)
return a;
pre = a + 1;
}
}
else
{
reverse(c.begin(), c.end());
if (s != 0)
{
root = c.back();
c.pop_back();
}
int last = s;
for (int a : c)
{
if (a <= t && t <= last)
return a;
last = a - 1;
}
}
return root;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
439 ms |
660 KB |
Output is correct |
2 |
Correct |
329 ms |
744 KB |
Output is correct |
3 |
Correct |
694 ms |
416 KB |
Output is correct |
4 |
Correct |
612 ms |
416 KB |
Output is correct |
5 |
Correct |
475 ms |
420 KB |
Output is correct |
6 |
Correct |
400 ms |
720 KB |
Output is correct |
7 |
Correct |
417 ms |
528 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
508 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
349 ms |
516 KB |
Output is correct |
2 |
Correct |
390 ms |
548 KB |
Output is correct |
3 |
Correct |
653 ms |
420 KB |
Output is correct |
4 |
Correct |
450 ms |
528 KB |
Output is correct |
5 |
Correct |
439 ms |
420 KB |
Output is correct |
6 |
Correct |
389 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
400 ms |
668 KB |
Output is correct |
2 |
Correct |
313 ms |
612 KB |
Output is correct |
3 |
Correct |
771 ms |
416 KB |
Output is correct |
4 |
Correct |
477 ms |
524 KB |
Output is correct |
5 |
Correct |
465 ms |
528 KB |
Output is correct |
6 |
Correct |
377 ms |
636 KB |
Output is correct |
7 |
Correct |
362 ms |
536 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
419 ms |
420 KB |
Output is correct |
12 |
Correct |
412 ms |
772 KB |
Output is correct |
13 |
Correct |
333 ms |
716 KB |
Output is correct |
14 |
Correct |
408 ms |
532 KB |
Output is correct |
15 |
Correct |
47 ms |
620 KB |
Output is correct |
16 |
Correct |
62 ms |
708 KB |
Output is correct |
17 |
Correct |
99 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
697 ms |
420 KB |
Output is correct |
2 |
Correct |
547 ms |
420 KB |
Output is correct |
3 |
Correct |
404 ms |
532 KB |
Output is correct |
4 |
Correct |
1 ms |
496 KB |
Output is correct |
5 |
Correct |
3 ms |
496 KB |
Output is correct |
6 |
Correct |
0 ms |
492 KB |
Output is correct |
7 |
Correct |
582 ms |
420 KB |
Output is correct |
8 |
Correct |
714 ms |
416 KB |
Output is correct |
9 |
Correct |
583 ms |
528 KB |
Output is correct |
10 |
Correct |
464 ms |
420 KB |
Output is correct |
11 |
Correct |
4 ms |
496 KB |
Output is correct |
12 |
Correct |
5 ms |
492 KB |
Output is correct |
13 |
Correct |
3 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
488 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
407 ms |
416 KB |
Output is correct |
17 |
Correct |
466 ms |
544 KB |
Output is correct |
18 |
Correct |
479 ms |
416 KB |
Output is correct |
19 |
Correct |
432 ms |
532 KB |
Output is correct |
20 |
Correct |
381 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
417 ms |
548 KB |
Output is correct |
2 |
Correct |
398 ms |
532 KB |
Output is correct |
3 |
Correct |
589 ms |
528 KB |
Output is correct |
4 |
Correct |
490 ms |
420 KB |
Output is correct |
5 |
Correct |
478 ms |
416 KB |
Output is correct |
6 |
Correct |
363 ms |
548 KB |
Output is correct |
7 |
Correct |
336 ms |
548 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
436 ms |
524 KB |
Output is correct |
12 |
Correct |
426 ms |
564 KB |
Output is correct |
13 |
Correct |
747 ms |
416 KB |
Output is correct |
14 |
Correct |
493 ms |
416 KB |
Output is correct |
15 |
Correct |
420 ms |
420 KB |
Output is correct |
16 |
Correct |
342 ms |
528 KB |
Output is correct |
17 |
Correct |
440 ms |
660 KB |
Output is correct |
18 |
Correct |
342 ms |
656 KB |
Output is correct |
19 |
Correct |
341 ms |
644 KB |
Output is correct |
20 |
Correct |
382 ms |
528 KB |
Output is correct |
21 |
Correct |
48 ms |
492 KB |
Output is correct |
22 |
Correct |
49 ms |
572 KB |
Output is correct |
23 |
Correct |
83 ms |
748 KB |
Output is correct |
24 |
Correct |
4 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
500 KB |
Output is correct |
28 |
Correct |
2 ms |
500 KB |
Output is correct |
29 |
Correct |
353 ms |
528 KB |
Output is correct |
30 |
Correct |
386 ms |
528 KB |
Output is correct |
31 |
Correct |
439 ms |
532 KB |
Output is correct |
32 |
Correct |
388 ms |
532 KB |
Output is correct |
33 |
Correct |
387 ms |
532 KB |
Output is correct |
34 |
Correct |
287 ms |
592 KB |
Output is correct |
35 |
Correct |
388 ms |
660 KB |
Output is correct |
36 |
Correct |
351 ms |
648 KB |
Output is correct |
37 |
Correct |
490 ms |
676 KB |
Output is correct |
38 |
Correct |
314 ms |
648 KB |
Output is correct |
39 |
Correct |
379 ms |
740 KB |
Output is correct |
40 |
Correct |
351 ms |
764 KB |
Output is correct |
41 |
Correct |
425 ms |
664 KB |
Output is correct |
42 |
Correct |
55 ms |
572 KB |
Output is correct |
43 |
Correct |
74 ms |
672 KB |
Output is correct |
44 |
Correct |
92 ms |
792 KB |
Output is correct |
45 |
Correct |
103 ms |
568 KB |
Output is correct |
46 |
Correct |
241 ms |
668 KB |
Output is correct |
47 |
Correct |
174 ms |
608 KB |
Output is correct |
48 |
Correct |
51 ms |
708 KB |
Output is correct |
49 |
Correct |
45 ms |
808 KB |
Output is correct |