#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
vector<vector<int>> g;
vector<bool> vis;
constexpr int inf = 1e9;
struct point {
int x, y;
point(int x, int y) : x(x), y(y) {}
point() = default;
point operator-(point other) {
return {x - other.x,y - other.y};
}
int operator*(point other) {
return x * other.y - y * other.x;
}
};
vector<point> m;
vector<point> points;
vector<int> ans;
// 1 to 2, 2 to 3
int getAngle(point p1, point p2, point p3) {
return (p3 - p1) * (p2 - p1);
}
void solve(int x, int par) {
auto prev = m[par];
for (auto child : g[x]) {
if (par == child) continue;
int sel = -1;
for (int i = 0; i < points.size(); ++i) {
auto p = points[i];
if (vis[i]) continue;
int ang = getAngle(m[x],p,points[sel == -1 ? 0 : sel]);
if (ang > 0 || sel == -1) {
sel = i;
}
}
m[child] = points[sel];
vis[sel] = true;
ans[sel] = child;
solve(child,x);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
g.resize(n + 1);
for (int i = 0; i < n - 1; ++i) {
int a, b; cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
points.resize(n);
vis.resize(n + 1);
int bestP = 0;
for (int i = 0; i < n; ++i) {
int x, y; cin >> x >> y;
points[i] = {x,y};
if (points[bestP].x > x) {
bestP = i;
}
if (points[bestP].x == x && points[bestP].y < y) {
bestP = i;
}
}
m.resize(n + 1);
m[0] = {0,0};
m[1] = points[bestP];
vis[bestP] = true;
ans.resize(n + 1);
ans[bestP] = 1;
solve(1,0);
for (int i = 0; i < n; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
Compilation message
Main.cpp: In function 'void solve(int, int)':
Main.cpp:37:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 0; i < points.size(); ++i) {
| ~~^~~~~~~~~~~~~~~
Main.cpp:33:10: warning: variable 'prev' set but not used [-Wunused-but-set-variable]
33 | auto prev = m[par];
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1544 ms |
8788 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
604 KB |
Output is correct |
2 |
Correct |
44 ms |
856 KB |
Output is correct |
3 |
Correct |
48 ms |
900 KB |
Output is correct |
4 |
Correct |
44 ms |
1104 KB |
Output is correct |
5 |
Correct |
44 ms |
1104 KB |
Output is correct |
6 |
Correct |
44 ms |
856 KB |
Output is correct |
7 |
Correct |
44 ms |
856 KB |
Output is correct |
8 |
Correct |
44 ms |
860 KB |
Output is correct |
9 |
Correct |
44 ms |
916 KB |
Output is correct |
10 |
Correct |
43 ms |
856 KB |
Output is correct |
11 |
Correct |
44 ms |
1104 KB |
Output is correct |
12 |
Correct |
44 ms |
856 KB |
Output is correct |
13 |
Correct |
44 ms |
860 KB |
Output is correct |
14 |
Correct |
44 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
604 KB |
Output is correct |
2 |
Correct |
44 ms |
856 KB |
Output is correct |
3 |
Correct |
48 ms |
900 KB |
Output is correct |
4 |
Correct |
44 ms |
1104 KB |
Output is correct |
5 |
Correct |
44 ms |
1104 KB |
Output is correct |
6 |
Correct |
44 ms |
856 KB |
Output is correct |
7 |
Correct |
44 ms |
856 KB |
Output is correct |
8 |
Correct |
44 ms |
860 KB |
Output is correct |
9 |
Correct |
44 ms |
916 KB |
Output is correct |
10 |
Correct |
43 ms |
856 KB |
Output is correct |
11 |
Correct |
44 ms |
1104 KB |
Output is correct |
12 |
Correct |
44 ms |
856 KB |
Output is correct |
13 |
Correct |
44 ms |
860 KB |
Output is correct |
14 |
Correct |
44 ms |
860 KB |
Output is correct |
15 |
Correct |
271 ms |
1368 KB |
Output is correct |
16 |
Correct |
290 ms |
1784 KB |
Output is correct |
17 |
Correct |
273 ms |
1776 KB |
Output is correct |
18 |
Correct |
266 ms |
1968 KB |
Output is correct |
19 |
Correct |
288 ms |
2132 KB |
Output is correct |
20 |
Correct |
268 ms |
1480 KB |
Output is correct |
21 |
Correct |
268 ms |
1616 KB |
Output is correct |
22 |
Correct |
269 ms |
1500 KB |
Output is correct |
23 |
Correct |
268 ms |
1620 KB |
Output is correct |
24 |
Correct |
273 ms |
1752 KB |
Output is correct |
25 |
Correct |
273 ms |
2132 KB |
Output is correct |
26 |
Correct |
265 ms |
2000 KB |
Output is correct |
27 |
Correct |
269 ms |
1488 KB |
Output is correct |
28 |
Correct |
264 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
604 KB |
Output is correct |
2 |
Correct |
44 ms |
856 KB |
Output is correct |
3 |
Correct |
48 ms |
900 KB |
Output is correct |
4 |
Correct |
44 ms |
1104 KB |
Output is correct |
5 |
Correct |
44 ms |
1104 KB |
Output is correct |
6 |
Correct |
44 ms |
856 KB |
Output is correct |
7 |
Correct |
44 ms |
856 KB |
Output is correct |
8 |
Correct |
44 ms |
860 KB |
Output is correct |
9 |
Correct |
44 ms |
916 KB |
Output is correct |
10 |
Correct |
43 ms |
856 KB |
Output is correct |
11 |
Correct |
44 ms |
1104 KB |
Output is correct |
12 |
Correct |
44 ms |
856 KB |
Output is correct |
13 |
Correct |
44 ms |
860 KB |
Output is correct |
14 |
Correct |
44 ms |
860 KB |
Output is correct |
15 |
Correct |
271 ms |
1368 KB |
Output is correct |
16 |
Correct |
290 ms |
1784 KB |
Output is correct |
17 |
Correct |
273 ms |
1776 KB |
Output is correct |
18 |
Correct |
266 ms |
1968 KB |
Output is correct |
19 |
Correct |
288 ms |
2132 KB |
Output is correct |
20 |
Correct |
268 ms |
1480 KB |
Output is correct |
21 |
Correct |
268 ms |
1616 KB |
Output is correct |
22 |
Correct |
269 ms |
1500 KB |
Output is correct |
23 |
Correct |
268 ms |
1620 KB |
Output is correct |
24 |
Correct |
273 ms |
1752 KB |
Output is correct |
25 |
Correct |
273 ms |
2132 KB |
Output is correct |
26 |
Correct |
265 ms |
2000 KB |
Output is correct |
27 |
Correct |
269 ms |
1488 KB |
Output is correct |
28 |
Correct |
264 ms |
1620 KB |
Output is correct |
29 |
Execution timed out |
1559 ms |
8760 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1544 ms |
8788 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |