#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef long long ll;
const int N = 1003;
vector<int> g[N];
int ti;
int tin[N], tout[N];
int d[N];
void dfs(int x, int p)
{
if (x == p)
d[x] = 0;
else
d[x] = d[p] + 1;
tin[x] = ti++;
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
if (h == p)
continue;
dfs(h, x);
}
tout[x] = ti++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
for (int i = 0; i < n; ++i)
g[i].clear();
for (int i = 0; i < n - 1; ++i)
{
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
ti = 0;
dfs(0, 0);
vector<int> ans;
for (int x = 0; x < n; ++x)
{
if (d[x] % 2 == 0)
ans.push_back(tin[x]);
else
ans.push_back(tout[x]);
}
v = ans;
sort(all(v));
for (int i = 0; i < sz(ans); ++i)
ans[i] = lower_bound(all(v), ans[i]) - v.begin();
return ans;
}
int find_next_station(int x, int y, std::vector<int> v)
{
for (int i = 0; i < sz(v); ++i)
{
if (v[i] == y)
return y;
}
if (x == 0)
{
sort(all(v));
for (int i = 0; i < sz(v) - 1; ++i)
{
if (v[i] < y && y < v[i + 1])
return v[i + 1];
}
return v[0];
}
if (x > v[0])
{
sort(all(v));
for (int i = 1; i < sz(v) - 1; ++i)
{
if (v[i] < y && y < v[i + 1])
return v[i];
}
if (v.back() < y && y < x)
return v.back();
return v[0];
}
else
{
sort(all(v));
for (int i = 0; i < sz(v) - 2; ++i)
{
if (v[i] < y && y < v[i + 1])
return v[i + 1];
}
if (x < y && y < v[0])
return v[0];
return v.back();
}
}
/*
1
5 2000
0 1
0 2
2 3
2 4
1
1 4 -1
*/
Compilation message
stations.cpp: In function 'void dfs(int, int)':
stations.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int i = 0; i < g[x].size(); ++i)
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
475 ms |
544 KB |
Output is correct |
2 |
Correct |
387 ms |
660 KB |
Output is correct |
3 |
Correct |
721 ms |
628 KB |
Output is correct |
4 |
Correct |
634 ms |
532 KB |
Output is correct |
5 |
Correct |
601 ms |
528 KB |
Output is correct |
6 |
Correct |
439 ms |
524 KB |
Output is correct |
7 |
Correct |
399 ms |
536 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
5 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
461 ms |
520 KB |
Output is correct |
2 |
Correct |
488 ms |
544 KB |
Output is correct |
3 |
Correct |
905 ms |
544 KB |
Output is correct |
4 |
Correct |
594 ms |
528 KB |
Output is correct |
5 |
Correct |
736 ms |
544 KB |
Output is correct |
6 |
Correct |
476 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
455 ms |
656 KB |
Output is correct |
2 |
Correct |
440 ms |
664 KB |
Output is correct |
3 |
Correct |
780 ms |
528 KB |
Output is correct |
4 |
Correct |
552 ms |
532 KB |
Output is correct |
5 |
Correct |
494 ms |
548 KB |
Output is correct |
6 |
Correct |
419 ms |
644 KB |
Output is correct |
7 |
Correct |
426 ms |
552 KB |
Output is correct |
8 |
Correct |
2 ms |
540 KB |
Output is correct |
9 |
Correct |
4 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
615 ms |
416 KB |
Output is correct |
12 |
Correct |
477 ms |
768 KB |
Output is correct |
13 |
Correct |
437 ms |
772 KB |
Output is correct |
14 |
Correct |
510 ms |
548 KB |
Output is correct |
15 |
Correct |
55 ms |
596 KB |
Output is correct |
16 |
Correct |
67 ms |
600 KB |
Output is correct |
17 |
Correct |
111 ms |
676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
719 ms |
524 KB |
Output is correct |
2 |
Correct |
641 ms |
544 KB |
Output is correct |
3 |
Correct |
588 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
5 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
459 ms |
532 KB |
Output is correct |
8 |
Correct |
825 ms |
524 KB |
Output is correct |
9 |
Correct |
714 ms |
532 KB |
Output is correct |
10 |
Correct |
561 ms |
548 KB |
Output is correct |
11 |
Correct |
6 ms |
628 KB |
Output is correct |
12 |
Correct |
5 ms |
492 KB |
Output is correct |
13 |
Correct |
5 ms |
620 KB |
Output is correct |
14 |
Correct |
5 ms |
584 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
435 ms |
532 KB |
Output is correct |
17 |
Correct |
501 ms |
548 KB |
Output is correct |
18 |
Correct |
585 ms |
416 KB |
Output is correct |
19 |
Correct |
481 ms |
536 KB |
Output is correct |
20 |
Correct |
425 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
518 ms |
660 KB |
Output is correct |
2 |
Correct |
443 ms |
520 KB |
Output is correct |
3 |
Correct |
984 ms |
524 KB |
Output is correct |
4 |
Correct |
692 ms |
528 KB |
Output is correct |
5 |
Correct |
547 ms |
548 KB |
Output is correct |
6 |
Correct |
476 ms |
656 KB |
Output is correct |
7 |
Correct |
391 ms |
544 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
5 ms |
500 KB |
Output is correct |
10 |
Correct |
0 ms |
500 KB |
Output is correct |
11 |
Correct |
401 ms |
524 KB |
Output is correct |
12 |
Correct |
530 ms |
544 KB |
Output is correct |
13 |
Correct |
935 ms |
592 KB |
Output is correct |
14 |
Correct |
654 ms |
536 KB |
Output is correct |
15 |
Correct |
627 ms |
420 KB |
Output is correct |
16 |
Correct |
445 ms |
524 KB |
Output is correct |
17 |
Correct |
630 ms |
544 KB |
Output is correct |
18 |
Correct |
528 ms |
756 KB |
Output is correct |
19 |
Correct |
392 ms |
732 KB |
Output is correct |
20 |
Correct |
478 ms |
536 KB |
Output is correct |
21 |
Correct |
56 ms |
600 KB |
Output is correct |
22 |
Correct |
71 ms |
544 KB |
Output is correct |
23 |
Correct |
110 ms |
544 KB |
Output is correct |
24 |
Correct |
5 ms |
748 KB |
Output is correct |
25 |
Correct |
5 ms |
620 KB |
Output is correct |
26 |
Correct |
4 ms |
492 KB |
Output is correct |
27 |
Correct |
4 ms |
632 KB |
Output is correct |
28 |
Correct |
2 ms |
628 KB |
Output is correct |
29 |
Correct |
552 ms |
536 KB |
Output is correct |
30 |
Correct |
476 ms |
532 KB |
Output is correct |
31 |
Correct |
562 ms |
548 KB |
Output is correct |
32 |
Correct |
592 ms |
536 KB |
Output is correct |
33 |
Correct |
367 ms |
544 KB |
Output is correct |
34 |
Correct |
320 ms |
532 KB |
Output is correct |
35 |
Correct |
462 ms |
720 KB |
Output is correct |
36 |
Correct |
458 ms |
656 KB |
Output is correct |
37 |
Correct |
433 ms |
652 KB |
Output is correct |
38 |
Correct |
507 ms |
524 KB |
Output is correct |
39 |
Correct |
438 ms |
656 KB |
Output is correct |
40 |
Correct |
485 ms |
760 KB |
Output is correct |
41 |
Correct |
465 ms |
668 KB |
Output is correct |
42 |
Correct |
69 ms |
528 KB |
Output is correct |
43 |
Correct |
108 ms |
672 KB |
Output is correct |
44 |
Correct |
147 ms |
540 KB |
Output is correct |
45 |
Correct |
140 ms |
544 KB |
Output is correct |
46 |
Correct |
281 ms |
612 KB |
Output is correct |
47 |
Correct |
317 ms |
548 KB |
Output is correct |
48 |
Correct |
73 ms |
780 KB |
Output is correct |
49 |
Correct |
64 ms |
828 KB |
Output is correct |