#include "stations.h"
#include "bits/stdc++.h"
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
int N, K, idx;
vvi adj;
vi in, out, parity;
void dfs(int v, int p)
{
in[v] = idx++;
parity[v] = parity[p] ^ 1;
for (int u : adj[v])
if (u != p)
dfs(u, v);
out[v] = idx++;
};
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v)
{
K = k;
N = n;
adj.clear();
adj.resize(N);
for (int i = 0; i < N - 1; ++i)
adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]);
idx = 0;
in.assign(N, -1), out.assign(N, -1), parity.assign(N, 0);
dfs(0, 0);
vi labels(N);
for (int i = 0; i < n; i++)
labels[i] = (parity[i]) ? in[i] : out[i];
vi distinct(all(labels));
sort(all(distinct));
map<int, int> dict;
for (int i = 0; i < sz(distinct); ++i)
dict[distinct[i]] = i;
for (int i = 0; i < sz(labels); ++i)
labels[i] = dict[labels[i]];
return labels;
}
int find_next_station(int s, int t, std::vector<int> c)
{
if (s < c[0])
{
// s has in parity
if (t < s)
return c.back(); // parent with highest out value
for (int i = 0; i < sz(c); ++i)
{
if (t <= c[i])
return c[i];
}
return c.back();
}
else
{
// s has out parity
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];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
513 ms |
672 KB |
Output is correct |
2 |
Correct |
485 ms |
620 KB |
Output is correct |
3 |
Correct |
721 ms |
420 KB |
Output is correct |
4 |
Correct |
651 ms |
508 KB |
Output is correct |
5 |
Correct |
364 ms |
416 KB |
Output is correct |
6 |
Correct |
315 ms |
672 KB |
Output is correct |
7 |
Correct |
251 ms |
632 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
496 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
544 KB |
Output is correct |
2 |
Correct |
456 ms |
624 KB |
Output is correct |
3 |
Correct |
1000 ms |
464 KB |
Output is correct |
4 |
Correct |
597 ms |
420 KB |
Output is correct |
5 |
Correct |
420 ms |
500 KB |
Output is correct |
6 |
Correct |
309 ms |
712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
375 ms |
676 KB |
Output is correct |
2 |
Correct |
220 ms |
544 KB |
Output is correct |
3 |
Correct |
1063 ms |
420 KB |
Output is correct |
4 |
Correct |
618 ms |
416 KB |
Output is correct |
5 |
Correct |
516 ms |
416 KB |
Output is correct |
6 |
Correct |
339 ms |
640 KB |
Output is correct |
7 |
Correct |
329 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
500 KB |
Output is correct |
11 |
Correct |
540 ms |
416 KB |
Output is correct |
12 |
Correct |
530 ms |
752 KB |
Output is correct |
13 |
Correct |
356 ms |
748 KB |
Output is correct |
14 |
Correct |
257 ms |
632 KB |
Output is correct |
15 |
Correct |
29 ms |
460 KB |
Output is correct |
16 |
Correct |
45 ms |
620 KB |
Output is correct |
17 |
Correct |
71 ms |
680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
497 ms |
512 KB |
Output is correct |
2 |
Correct |
621 ms |
416 KB |
Output is correct |
3 |
Correct |
707 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
0 ms |
488 KB |
Output is correct |
7 |
Correct |
568 ms |
504 KB |
Output is correct |
8 |
Correct |
766 ms |
416 KB |
Output is correct |
9 |
Correct |
635 ms |
500 KB |
Output is correct |
10 |
Correct |
399 ms |
416 KB |
Output is correct |
11 |
Correct |
3 ms |
492 KB |
Output is correct |
12 |
Correct |
4 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
342 ms |
416 KB |
Output is correct |
17 |
Correct |
340 ms |
504 KB |
Output is correct |
18 |
Correct |
445 ms |
416 KB |
Output is correct |
19 |
Correct |
386 ms |
416 KB |
Output is correct |
20 |
Correct |
380 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
366 ms |
608 KB |
Output is correct |
2 |
Correct |
373 ms |
696 KB |
Output is correct |
3 |
Correct |
682 ms |
508 KB |
Output is correct |
4 |
Correct |
454 ms |
420 KB |
Output is correct |
5 |
Correct |
378 ms |
416 KB |
Output is correct |
6 |
Correct |
368 ms |
684 KB |
Output is correct |
7 |
Correct |
372 ms |
636 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
420 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
403 ms |
548 KB |
Output is correct |
12 |
Correct |
461 ms |
544 KB |
Output is correct |
13 |
Correct |
812 ms |
504 KB |
Output is correct |
14 |
Correct |
486 ms |
416 KB |
Output is correct |
15 |
Correct |
481 ms |
504 KB |
Output is correct |
16 |
Correct |
380 ms |
544 KB |
Output is correct |
17 |
Correct |
423 ms |
508 KB |
Output is correct |
18 |
Correct |
349 ms |
764 KB |
Output is correct |
19 |
Correct |
413 ms |
716 KB |
Output is correct |
20 |
Correct |
307 ms |
544 KB |
Output is correct |
21 |
Correct |
45 ms |
472 KB |
Output is correct |
22 |
Correct |
56 ms |
620 KB |
Output is correct |
23 |
Correct |
80 ms |
544 KB |
Output is correct |
24 |
Correct |
3 ms |
500 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
500 KB |
Output is correct |
27 |
Correct |
2 ms |
500 KB |
Output is correct |
28 |
Correct |
0 ms |
492 KB |
Output is correct |
29 |
Correct |
498 ms |
416 KB |
Output is correct |
30 |
Correct |
310 ms |
416 KB |
Output is correct |
31 |
Correct |
399 ms |
504 KB |
Output is correct |
32 |
Correct |
342 ms |
504 KB |
Output is correct |
33 |
Correct |
349 ms |
500 KB |
Output is correct |
34 |
Correct |
246 ms |
672 KB |
Output is correct |
35 |
Correct |
295 ms |
872 KB |
Output is correct |
36 |
Correct |
323 ms |
708 KB |
Output is correct |
37 |
Correct |
328 ms |
720 KB |
Output is correct |
38 |
Correct |
398 ms |
716 KB |
Output is correct |
39 |
Correct |
399 ms |
720 KB |
Output is correct |
40 |
Correct |
399 ms |
632 KB |
Output is correct |
41 |
Correct |
380 ms |
716 KB |
Output is correct |
42 |
Correct |
44 ms |
576 KB |
Output is correct |
43 |
Correct |
102 ms |
548 KB |
Output is correct |
44 |
Correct |
97 ms |
544 KB |
Output is correct |
45 |
Correct |
117 ms |
544 KB |
Output is correct |
46 |
Correct |
284 ms |
544 KB |
Output is correct |
47 |
Correct |
220 ms |
632 KB |
Output is correct |
48 |
Correct |
41 ms |
804 KB |
Output is correct |
49 |
Correct |
49 ms |
676 KB |
Output is correct |