This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* 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>{x,y}<array<ll,2>{other.x,other.y};
}
};
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];
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;
int cur = l + 1;
for(int u: g[v]){
if(u==par) continue;
dfs2(u, v, p, cur);
cur += s[u];
}
}
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';
// }
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 (stderr)
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:94:15: warning: unused variable 'aa' [-Wunused-variable]
94 | int tt = 1, aa;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |