/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
const int N_MAX = 1002;
vector <int> edges[N_MAX];
int sub[N_MAX];
void dfs (int u, int parent = -1)
{
sub[u] = 1;
for(int v : edges[u])
if(v != parent)
{
dfs(v, u);
sub[u] += sub[v];
}
}
int lb[N_MAX];
void solve (int u, int l, int r, bool type, int parent = -1)
{
if(type == 0)
lb[u] = l++;
else
lb[u] = r--;
for(int v : edges[u])
if(v != parent)
{
solve(v, l, l + sub[v] - 1, !type, u);
l += sub[v];
}
}
vector <int> label (int n, int k, vector <int> u, vector <int> v)
{
for(int i = 1; i < n; i++)
{
int a = u[i - 1] + 1;
int b = v[i - 1] + 1;
edges[a].push_back(b);
edges[b].push_back(a);
}
dfs(1);
solve(1, 1, n, 0);
vector <int> labels(n);
for(int i = 1; i <= n; i++)
labels[i - 1] = lb[i] - 1;
for(int i = 1; i <= n; i++)
edges[i].clear();
return labels;
}
int find_next_station (int s, int t, vector <int> c)
{
bool type = 1;
for(int u : c)
type &= (u < s);
if(type == 0)
{
sort(c.begin(), c.end());
int root = c.back();
c.pop_back();
int l = s + 1;
for(int u : c)
{
if(l <= t && t <= u)
return u;
l = u + 1;
}
return root;
}
else
{
sort(c.begin(), c.end());
reverse(c.begin(), c.end());
int root = c.back();
c.pop_back();
int r = s - 1;
for(int u : c)
{
if(u <= t && t <= r)
return u;
r = u - 1;
}
return root;
}
}
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:61:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
61 | for(int i = 1; i <= n; i++)
| ^~~
stations.cpp:63:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
63 | return labels;
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
558 ms |
864 KB |
Output is correct |
2 |
Correct |
430 ms |
856 KB |
Output is correct |
3 |
Correct |
979 ms |
736 KB |
Output is correct |
4 |
Correct |
737 ms |
932 KB |
Output is correct |
5 |
Correct |
529 ms |
1024 KB |
Output is correct |
6 |
Correct |
501 ms |
1072 KB |
Output is correct |
7 |
Correct |
541 ms |
1036 KB |
Output is correct |
8 |
Correct |
3 ms |
864 KB |
Output is correct |
9 |
Correct |
5 ms |
736 KB |
Output is correct |
10 |
Correct |
2 ms |
864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
440 ms |
736 KB |
Output is correct |
2 |
Correct |
596 ms |
896 KB |
Output is correct |
3 |
Correct |
1075 ms |
1068 KB |
Output is correct |
4 |
Correct |
677 ms |
736 KB |
Output is correct |
5 |
Correct |
636 ms |
940 KB |
Output is correct |
6 |
Correct |
527 ms |
892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
576 ms |
1060 KB |
Output is correct |
2 |
Correct |
550 ms |
1068 KB |
Output is correct |
3 |
Correct |
922 ms |
984 KB |
Output is correct |
4 |
Correct |
708 ms |
864 KB |
Output is correct |
5 |
Correct |
592 ms |
940 KB |
Output is correct |
6 |
Correct |
428 ms |
1068 KB |
Output is correct |
7 |
Correct |
479 ms |
1092 KB |
Output is correct |
8 |
Correct |
3 ms |
736 KB |
Output is correct |
9 |
Correct |
5 ms |
864 KB |
Output is correct |
10 |
Correct |
2 ms |
864 KB |
Output is correct |
11 |
Correct |
587 ms |
864 KB |
Output is correct |
12 |
Correct |
477 ms |
1124 KB |
Output is correct |
13 |
Correct |
445 ms |
992 KB |
Output is correct |
14 |
Correct |
397 ms |
864 KB |
Output is correct |
15 |
Correct |
58 ms |
932 KB |
Output is correct |
16 |
Correct |
73 ms |
992 KB |
Output is correct |
17 |
Correct |
109 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
823 ms |
736 KB |
Output is correct |
2 |
Correct |
833 ms |
864 KB |
Output is correct |
3 |
Correct |
676 ms |
864 KB |
Output is correct |
4 |
Correct |
3 ms |
936 KB |
Output is correct |
5 |
Correct |
4 ms |
992 KB |
Output is correct |
6 |
Correct |
2 ms |
940 KB |
Output is correct |
7 |
Correct |
611 ms |
940 KB |
Output is correct |
8 |
Correct |
915 ms |
736 KB |
Output is correct |
9 |
Correct |
677 ms |
940 KB |
Output is correct |
10 |
Correct |
563 ms |
1108 KB |
Output is correct |
11 |
Correct |
6 ms |
736 KB |
Output is correct |
12 |
Correct |
6 ms |
984 KB |
Output is correct |
13 |
Correct |
4 ms |
952 KB |
Output is correct |
14 |
Correct |
4 ms |
952 KB |
Output is correct |
15 |
Correct |
2 ms |
940 KB |
Output is correct |
16 |
Correct |
465 ms |
992 KB |
Output is correct |
17 |
Correct |
449 ms |
940 KB |
Output is correct |
18 |
Correct |
494 ms |
944 KB |
Output is correct |
19 |
Correct |
605 ms |
736 KB |
Output is correct |
20 |
Correct |
569 ms |
1068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
630 ms |
1248 KB |
Output is correct |
2 |
Correct |
530 ms |
864 KB |
Output is correct |
3 |
Correct |
882 ms |
1100 KB |
Output is correct |
4 |
Correct |
643 ms |
940 KB |
Output is correct |
5 |
Correct |
611 ms |
1108 KB |
Output is correct |
6 |
Correct |
416 ms |
1112 KB |
Output is correct |
7 |
Correct |
427 ms |
1116 KB |
Output is correct |
8 |
Correct |
3 ms |
864 KB |
Output is correct |
9 |
Correct |
6 ms |
736 KB |
Output is correct |
10 |
Correct |
2 ms |
864 KB |
Output is correct |
11 |
Correct |
525 ms |
880 KB |
Output is correct |
12 |
Correct |
593 ms |
884 KB |
Output is correct |
13 |
Correct |
874 ms |
992 KB |
Output is correct |
14 |
Correct |
690 ms |
1120 KB |
Output is correct |
15 |
Correct |
682 ms |
944 KB |
Output is correct |
16 |
Correct |
559 ms |
864 KB |
Output is correct |
17 |
Correct |
552 ms |
944 KB |
Output is correct |
18 |
Correct |
431 ms |
1004 KB |
Output is correct |
19 |
Correct |
515 ms |
1204 KB |
Output is correct |
20 |
Correct |
487 ms |
864 KB |
Output is correct |
21 |
Correct |
62 ms |
896 KB |
Output is correct |
22 |
Correct |
92 ms |
1204 KB |
Output is correct |
23 |
Correct |
101 ms |
884 KB |
Output is correct |
24 |
Correct |
7 ms |
956 KB |
Output is correct |
25 |
Correct |
5 ms |
892 KB |
Output is correct |
26 |
Correct |
5 ms |
864 KB |
Output is correct |
27 |
Correct |
3 ms |
940 KB |
Output is correct |
28 |
Correct |
2 ms |
864 KB |
Output is correct |
29 |
Correct |
584 ms |
952 KB |
Output is correct |
30 |
Correct |
599 ms |
940 KB |
Output is correct |
31 |
Correct |
528 ms |
944 KB |
Output is correct |
32 |
Correct |
522 ms |
940 KB |
Output is correct |
33 |
Correct |
540 ms |
936 KB |
Output is correct |
34 |
Correct |
440 ms |
1084 KB |
Output is correct |
35 |
Correct |
516 ms |
1120 KB |
Output is correct |
36 |
Correct |
547 ms |
1076 KB |
Output is correct |
37 |
Correct |
492 ms |
1100 KB |
Output is correct |
38 |
Correct |
510 ms |
1152 KB |
Output is correct |
39 |
Correct |
437 ms |
1240 KB |
Output is correct |
40 |
Correct |
473 ms |
1112 KB |
Output is correct |
41 |
Correct |
549 ms |
1232 KB |
Output is correct |
42 |
Correct |
60 ms |
1144 KB |
Output is correct |
43 |
Correct |
132 ms |
892 KB |
Output is correct |
44 |
Correct |
131 ms |
864 KB |
Output is correct |
45 |
Correct |
165 ms |
1116 KB |
Output is correct |
46 |
Correct |
328 ms |
884 KB |
Output is correct |
47 |
Correct |
360 ms |
1236 KB |
Output is correct |
48 |
Correct |
63 ms |
1136 KB |
Output is correct |
49 |
Correct |
76 ms |
864 KB |
Output is correct |