#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
#define MAX 200000
//para las coordenadas
#define x first
#define y second
lli n,a,b,ini,cont;
lli res[MAX+2];
vector<lli> hijos[MAX+2],orden;
pll coord[MAX+2];
void dfs(lli pos,lli padre){
if (pos != 1) res[ orden[cont++] ] = pos;
for(auto h : hijos[pos]) {
if(h == padre) continue;
dfs(h,pos);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
rep(i,1,n-1) {
cin >> a >> b;
hijos[a].push_back(b);
hijos[b].push_back(a);
}
rep(i,1,n) {
cin >> a >> b;
coord[i] = {a,b};
if (coord[ini].x == 0 || coord[ini].x > a) ini = i;
}
rep(i,1,n) {
if (i==ini) continue;
orden.push_back(i);
}
sort(orden.begin(), orden.end(), [] (lli a, lli b) {
lli a1 = coord[a].x - coord[ini].x;
lli b1 = coord[a].y - coord[ini].y;
lli a2 = coord[b].x - coord[ini].x;
lli b2 = coord[b].y - coord[ini].y;
if( (a1*b2) > (a2*b1) ) return true;
else return false;
});
res[ini] = 1;
cont = 0;
dfs(1,0);
rep(i,1,n) cout << res[i] << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
17424 KB |
Output is correct |
2 |
Correct |
85 ms |
20272 KB |
Output is correct |
3 |
Correct |
71 ms |
19576 KB |
Output is correct |
4 |
Correct |
79 ms |
21440 KB |
Output is correct |
5 |
Correct |
80 ms |
20760 KB |
Output is correct |
6 |
Correct |
98 ms |
17764 KB |
Output is correct |
7 |
Correct |
69 ms |
16948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5460 KB |
Output is correct |
2 |
Correct |
6 ms |
5460 KB |
Output is correct |
3 |
Correct |
6 ms |
5460 KB |
Output is correct |
4 |
Correct |
6 ms |
5560 KB |
Output is correct |
5 |
Correct |
5 ms |
5576 KB |
Output is correct |
6 |
Correct |
5 ms |
5448 KB |
Output is correct |
7 |
Correct |
4 ms |
5436 KB |
Output is correct |
8 |
Correct |
4 ms |
5480 KB |
Output is correct |
9 |
Correct |
5 ms |
5588 KB |
Output is correct |
10 |
Correct |
4 ms |
5460 KB |
Output is correct |
11 |
Correct |
4 ms |
5576 KB |
Output is correct |
12 |
Correct |
4 ms |
5460 KB |
Output is correct |
13 |
Correct |
4 ms |
5424 KB |
Output is correct |
14 |
Correct |
4 ms |
5460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5460 KB |
Output is correct |
2 |
Correct |
6 ms |
5460 KB |
Output is correct |
3 |
Correct |
6 ms |
5460 KB |
Output is correct |
4 |
Correct |
6 ms |
5560 KB |
Output is correct |
5 |
Correct |
5 ms |
5576 KB |
Output is correct |
6 |
Correct |
5 ms |
5448 KB |
Output is correct |
7 |
Correct |
4 ms |
5436 KB |
Output is correct |
8 |
Correct |
4 ms |
5480 KB |
Output is correct |
9 |
Correct |
5 ms |
5588 KB |
Output is correct |
10 |
Correct |
4 ms |
5460 KB |
Output is correct |
11 |
Correct |
4 ms |
5576 KB |
Output is correct |
12 |
Correct |
4 ms |
5460 KB |
Output is correct |
13 |
Correct |
4 ms |
5424 KB |
Output is correct |
14 |
Correct |
4 ms |
5460 KB |
Output is correct |
15 |
Correct |
7 ms |
6192 KB |
Output is correct |
16 |
Correct |
7 ms |
6384 KB |
Output is correct |
17 |
Correct |
8 ms |
6356 KB |
Output is correct |
18 |
Correct |
7 ms |
6484 KB |
Output is correct |
19 |
Correct |
10 ms |
6420 KB |
Output is correct |
20 |
Correct |
10 ms |
6228 KB |
Output is correct |
21 |
Correct |
7 ms |
6228 KB |
Output is correct |
22 |
Correct |
7 ms |
6100 KB |
Output is correct |
23 |
Correct |
7 ms |
6320 KB |
Output is correct |
24 |
Correct |
8 ms |
6380 KB |
Output is correct |
25 |
Correct |
8 ms |
6548 KB |
Output is correct |
26 |
Correct |
8 ms |
6356 KB |
Output is correct |
27 |
Correct |
8 ms |
6228 KB |
Output is correct |
28 |
Correct |
9 ms |
6152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5460 KB |
Output is correct |
2 |
Correct |
6 ms |
5460 KB |
Output is correct |
3 |
Correct |
6 ms |
5460 KB |
Output is correct |
4 |
Correct |
6 ms |
5560 KB |
Output is correct |
5 |
Correct |
5 ms |
5576 KB |
Output is correct |
6 |
Correct |
5 ms |
5448 KB |
Output is correct |
7 |
Correct |
4 ms |
5436 KB |
Output is correct |
8 |
Correct |
4 ms |
5480 KB |
Output is correct |
9 |
Correct |
5 ms |
5588 KB |
Output is correct |
10 |
Correct |
4 ms |
5460 KB |
Output is correct |
11 |
Correct |
4 ms |
5576 KB |
Output is correct |
12 |
Correct |
4 ms |
5460 KB |
Output is correct |
13 |
Correct |
4 ms |
5424 KB |
Output is correct |
14 |
Correct |
4 ms |
5460 KB |
Output is correct |
15 |
Correct |
7 ms |
6192 KB |
Output is correct |
16 |
Correct |
7 ms |
6384 KB |
Output is correct |
17 |
Correct |
8 ms |
6356 KB |
Output is correct |
18 |
Correct |
7 ms |
6484 KB |
Output is correct |
19 |
Correct |
10 ms |
6420 KB |
Output is correct |
20 |
Correct |
10 ms |
6228 KB |
Output is correct |
21 |
Correct |
7 ms |
6228 KB |
Output is correct |
22 |
Correct |
7 ms |
6100 KB |
Output is correct |
23 |
Correct |
7 ms |
6320 KB |
Output is correct |
24 |
Correct |
8 ms |
6380 KB |
Output is correct |
25 |
Correct |
8 ms |
6548 KB |
Output is correct |
26 |
Correct |
8 ms |
6356 KB |
Output is correct |
27 |
Correct |
8 ms |
6228 KB |
Output is correct |
28 |
Correct |
9 ms |
6152 KB |
Output is correct |
29 |
Correct |
55 ms |
13756 KB |
Output is correct |
30 |
Correct |
50 ms |
15784 KB |
Output is correct |
31 |
Correct |
48 ms |
15532 KB |
Output is correct |
32 |
Correct |
61 ms |
16092 KB |
Output is correct |
33 |
Correct |
49 ms |
15712 KB |
Output is correct |
34 |
Correct |
50 ms |
13984 KB |
Output is correct |
35 |
Correct |
50 ms |
13676 KB |
Output is correct |
36 |
Correct |
56 ms |
12596 KB |
Output is correct |
37 |
Correct |
50 ms |
15132 KB |
Output is correct |
38 |
Correct |
49 ms |
15812 KB |
Output is correct |
39 |
Correct |
52 ms |
15668 KB |
Output is correct |
40 |
Correct |
47 ms |
14628 KB |
Output is correct |
41 |
Correct |
40 ms |
12864 KB |
Output is correct |
42 |
Correct |
47 ms |
13692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
17424 KB |
Output is correct |
2 |
Correct |
85 ms |
20272 KB |
Output is correct |
3 |
Correct |
71 ms |
19576 KB |
Output is correct |
4 |
Correct |
79 ms |
21440 KB |
Output is correct |
5 |
Correct |
80 ms |
20760 KB |
Output is correct |
6 |
Correct |
98 ms |
17764 KB |
Output is correct |
7 |
Correct |
69 ms |
16948 KB |
Output is correct |
8 |
Correct |
5 ms |
5460 KB |
Output is correct |
9 |
Correct |
6 ms |
5460 KB |
Output is correct |
10 |
Correct |
6 ms |
5460 KB |
Output is correct |
11 |
Correct |
6 ms |
5560 KB |
Output is correct |
12 |
Correct |
5 ms |
5576 KB |
Output is correct |
13 |
Correct |
5 ms |
5448 KB |
Output is correct |
14 |
Correct |
4 ms |
5436 KB |
Output is correct |
15 |
Correct |
4 ms |
5480 KB |
Output is correct |
16 |
Correct |
5 ms |
5588 KB |
Output is correct |
17 |
Correct |
4 ms |
5460 KB |
Output is correct |
18 |
Correct |
4 ms |
5576 KB |
Output is correct |
19 |
Correct |
4 ms |
5460 KB |
Output is correct |
20 |
Correct |
4 ms |
5424 KB |
Output is correct |
21 |
Correct |
4 ms |
5460 KB |
Output is correct |
22 |
Correct |
7 ms |
6192 KB |
Output is correct |
23 |
Correct |
7 ms |
6384 KB |
Output is correct |
24 |
Correct |
8 ms |
6356 KB |
Output is correct |
25 |
Correct |
7 ms |
6484 KB |
Output is correct |
26 |
Correct |
10 ms |
6420 KB |
Output is correct |
27 |
Correct |
10 ms |
6228 KB |
Output is correct |
28 |
Correct |
7 ms |
6228 KB |
Output is correct |
29 |
Correct |
7 ms |
6100 KB |
Output is correct |
30 |
Correct |
7 ms |
6320 KB |
Output is correct |
31 |
Correct |
8 ms |
6380 KB |
Output is correct |
32 |
Correct |
8 ms |
6548 KB |
Output is correct |
33 |
Correct |
8 ms |
6356 KB |
Output is correct |
34 |
Correct |
8 ms |
6228 KB |
Output is correct |
35 |
Correct |
9 ms |
6152 KB |
Output is correct |
36 |
Correct |
55 ms |
13756 KB |
Output is correct |
37 |
Correct |
50 ms |
15784 KB |
Output is correct |
38 |
Correct |
48 ms |
15532 KB |
Output is correct |
39 |
Correct |
61 ms |
16092 KB |
Output is correct |
40 |
Correct |
49 ms |
15712 KB |
Output is correct |
41 |
Correct |
50 ms |
13984 KB |
Output is correct |
42 |
Correct |
50 ms |
13676 KB |
Output is correct |
43 |
Correct |
56 ms |
12596 KB |
Output is correct |
44 |
Correct |
50 ms |
15132 KB |
Output is correct |
45 |
Correct |
49 ms |
15812 KB |
Output is correct |
46 |
Correct |
52 ms |
15668 KB |
Output is correct |
47 |
Correct |
47 ms |
14628 KB |
Output is correct |
48 |
Correct |
40 ms |
12864 KB |
Output is correct |
49 |
Correct |
47 ms |
13692 KB |
Output is correct |
50 |
Correct |
77 ms |
18732 KB |
Output is correct |
51 |
Correct |
156 ms |
31908 KB |
Output is correct |
52 |
Correct |
151 ms |
31168 KB |
Output is correct |
53 |
Correct |
153 ms |
30748 KB |
Output is correct |
54 |
Correct |
153 ms |
34616 KB |
Output is correct |
55 |
Correct |
147 ms |
27716 KB |
Output is correct |
56 |
Correct |
151 ms |
26296 KB |
Output is correct |
57 |
Correct |
26 ms |
9720 KB |
Output is correct |
58 |
Correct |
195 ms |
29752 KB |
Output is correct |
59 |
Correct |
148 ms |
30496 KB |
Output is correct |
60 |
Correct |
172 ms |
33968 KB |
Output is correct |
61 |
Correct |
146 ms |
29880 KB |
Output is correct |
62 |
Correct |
26 ms |
9892 KB |
Output is correct |
63 |
Correct |
146 ms |
26276 KB |
Output is correct |