/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
struct P{
ll x, y;
void read(){
cin >> x >> y;
}
ll operator * (const P &other) const{
return x * other.y - y * other.x;
}
P operator - (const P &other) const{
return P{x-other.x, y-other.y};
}
bool operator < (const P&other)const{
return array<ll,2>{y,-x}>array<ll,2>{other.y,-other.x};
}
};
struct Poly{
vector<pair<P, int>> poly;
Poly(int n){
poly.resize(n);
for(int i = 0; i < n; ++i)
poly[i].first.read(), poly[i].second = i;
}
void ch(){
sort(all(poly));
vector<pair<P, int>> c;
for(int i = 0; i < poly.size(); ++i){
while(c.size() > 1 && (poly[i].first - c[c.size() - 2].first) * (c.back().first - c[c.size() - 2].first) < 0) c.pop_back();
c.pb(poly[i]);
}
c.pop_back();
reverse(all(poly));
for(int i = 0; i < poly.size(); ++i){
while(c.size() > 1 && (poly[i].first - c[c.size() - 2].first) * (c.back().first - c[c.size() - 2].first) < 0) c.pop_back();
c.pb(poly[i]);
}
c.pop_back();
poly = c;
}
};
int n, s[N], pos[N];
vector<int> g[N];
vector<bool> vis;
void dfs(int v, int p){
s[v] = 1;
for(int u: g[v]){
if(u != p) dfs(u, v), s[v] += s[u];
}
}
void dfs2(int v, int par, Poly &p, int l){
pos[p.poly[l].second] = v;
vis[p.poly[l].second] = 1;
// cout << v << ' ' << par << '\n';
// cout << p.poly[l].second << '\n';
for(int u: g[v]){
if(u==par) continue;
int po = -1;
for(int i = 0; i < n; ++i){
if(!vis[p.poly[i].second]){
if(po == -1) po = i;
else{
if((p.poly[po].first - p.poly[l].first) * (p.poly[i].first - p.poly[l].first) > 0){
po = i;
}
}
}
}
dfs2(u, v, p, po);
}
}
void solve(){
cin >> n;
for(int i = 0; i < n-1; ++i){
int u, v; cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
Poly p(n);
// p.ch();
// assert(p.poly.size()==n);
// for(auto pp: p.poly){
// cout << pp.first.x << ' ' << pp.first.y << ' ' << pp.second << '\n';
// }
sort(all(p.poly));
vis.resize(n);
dfs(1, 1);
dfs2(1, 1, p, 0);
for(int i = 0; i < n; ++i) cout << pos[i] << ' ';
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message
Main.cpp: In member function 'void Poly::ch()':
Main.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<P, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i = 0; i < poly.size(); ++i){
| ~~^~~~~~~~~~~~~
Main.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<P, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i = 0; i < poly.size(); ++i){
| ~~^~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:109:15: warning: unused variable 'aa' [-Wunused-variable]
109 | int tt = 1, aa;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1530 ms |
33360 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
27484 KB |
Output is correct |
2 |
Correct |
56 ms |
27484 KB |
Output is correct |
3 |
Correct |
57 ms |
27712 KB |
Output is correct |
4 |
Correct |
56 ms |
27892 KB |
Output is correct |
5 |
Correct |
57 ms |
27736 KB |
Output is correct |
6 |
Correct |
55 ms |
27636 KB |
Output is correct |
7 |
Correct |
56 ms |
27700 KB |
Output is correct |
8 |
Correct |
57 ms |
27624 KB |
Output is correct |
9 |
Correct |
57 ms |
27736 KB |
Output is correct |
10 |
Correct |
56 ms |
27740 KB |
Output is correct |
11 |
Correct |
57 ms |
27736 KB |
Output is correct |
12 |
Correct |
56 ms |
27736 KB |
Output is correct |
13 |
Correct |
57 ms |
27484 KB |
Output is correct |
14 |
Correct |
57 ms |
27736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
27484 KB |
Output is correct |
2 |
Correct |
56 ms |
27484 KB |
Output is correct |
3 |
Correct |
57 ms |
27712 KB |
Output is correct |
4 |
Correct |
56 ms |
27892 KB |
Output is correct |
5 |
Correct |
57 ms |
27736 KB |
Output is correct |
6 |
Correct |
55 ms |
27636 KB |
Output is correct |
7 |
Correct |
56 ms |
27700 KB |
Output is correct |
8 |
Correct |
57 ms |
27624 KB |
Output is correct |
9 |
Correct |
57 ms |
27736 KB |
Output is correct |
10 |
Correct |
56 ms |
27740 KB |
Output is correct |
11 |
Correct |
57 ms |
27736 KB |
Output is correct |
12 |
Correct |
56 ms |
27736 KB |
Output is correct |
13 |
Correct |
57 ms |
27484 KB |
Output is correct |
14 |
Correct |
57 ms |
27736 KB |
Output is correct |
15 |
Correct |
309 ms |
28136 KB |
Output is correct |
16 |
Correct |
322 ms |
28760 KB |
Output is correct |
17 |
Correct |
319 ms |
28252 KB |
Output is correct |
18 |
Correct |
323 ms |
29264 KB |
Output is correct |
19 |
Correct |
324 ms |
28764 KB |
Output is correct |
20 |
Correct |
330 ms |
28240 KB |
Output is correct |
21 |
Correct |
320 ms |
28252 KB |
Output is correct |
22 |
Correct |
323 ms |
28240 KB |
Output is correct |
23 |
Correct |
320 ms |
28464 KB |
Output is correct |
24 |
Correct |
319 ms |
28372 KB |
Output is correct |
25 |
Correct |
322 ms |
28848 KB |
Output is correct |
26 |
Correct |
319 ms |
28752 KB |
Output is correct |
27 |
Correct |
330 ms |
28132 KB |
Output is correct |
28 |
Correct |
320 ms |
28508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
27484 KB |
Output is correct |
2 |
Correct |
56 ms |
27484 KB |
Output is correct |
3 |
Correct |
57 ms |
27712 KB |
Output is correct |
4 |
Correct |
56 ms |
27892 KB |
Output is correct |
5 |
Correct |
57 ms |
27736 KB |
Output is correct |
6 |
Correct |
55 ms |
27636 KB |
Output is correct |
7 |
Correct |
56 ms |
27700 KB |
Output is correct |
8 |
Correct |
57 ms |
27624 KB |
Output is correct |
9 |
Correct |
57 ms |
27736 KB |
Output is correct |
10 |
Correct |
56 ms |
27740 KB |
Output is correct |
11 |
Correct |
57 ms |
27736 KB |
Output is correct |
12 |
Correct |
56 ms |
27736 KB |
Output is correct |
13 |
Correct |
57 ms |
27484 KB |
Output is correct |
14 |
Correct |
57 ms |
27736 KB |
Output is correct |
15 |
Correct |
309 ms |
28136 KB |
Output is correct |
16 |
Correct |
322 ms |
28760 KB |
Output is correct |
17 |
Correct |
319 ms |
28252 KB |
Output is correct |
18 |
Correct |
323 ms |
29264 KB |
Output is correct |
19 |
Correct |
324 ms |
28764 KB |
Output is correct |
20 |
Correct |
330 ms |
28240 KB |
Output is correct |
21 |
Correct |
320 ms |
28252 KB |
Output is correct |
22 |
Correct |
323 ms |
28240 KB |
Output is correct |
23 |
Correct |
320 ms |
28464 KB |
Output is correct |
24 |
Correct |
319 ms |
28372 KB |
Output is correct |
25 |
Correct |
322 ms |
28848 KB |
Output is correct |
26 |
Correct |
319 ms |
28752 KB |
Output is correct |
27 |
Correct |
330 ms |
28132 KB |
Output is correct |
28 |
Correct |
320 ms |
28508 KB |
Output is correct |
29 |
Execution timed out |
1534 ms |
33896 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1530 ms |
33360 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |