C. Paint Tree
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a tree with n vertexes and n points on a plane, no three points lie on one straight line.

Your task is to paint the given tree on a plane, using the given points as vertexes.

That is, you should correspond each vertex of the tree to exactly one point and each point should correspond to a vertex. If two vertexes of the tree are connected by an edge, then the corresponding points should have a segment painted between them. The segments that correspond to non-adjacent edges, should not have common points. The segments that correspond to adjacent edges should have exactly one common point.

Input

The first line contains an integer n (1 ≤ n ≤ 1500) — the number of vertexes on a tree (as well as the number of chosen points on the plane).

Each of the next n - 1 lines contains two space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the numbers of tree vertexes connected by the i-th edge.

Each of the next n lines contain two space-separated integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th point on the plane. No three points lie on one straight line.

It is guaranteed that under given constraints problem has a solution.

Output

Print n distinct space-separated integers from 1 to n: the i-th number must equal the number of the vertex to place at the i-th point (the points are numbered in the order, in which they are listed in the input).

If there are several solutions, print any of them.

Examples
Input
3
1 3
2 3
0 0
1 1
2 0
Output
1 3 2
Input
4
1 2
2 3
1 4
-1 -2
3 5
-3 3
2 0
Output
4 2 1 3
【分析】题意比较简单。给你一棵n个节点的树,再给你几何平面内的n个点,没有三点共线,
问你能不能用着n个点在几何平面内表现出来,线段除了顶点处无其他交点。
由于没有3点共线的情况,所以解总是存在的。
我们考虑以当前平面左下角的点p作为树根,对平面上的点以p做基准进行极角排序,则所有点与p点的连线都不会有除了p以外的交点。
现在我们已经会填树根处的点了,对于树根的每个子节点,我们都可以递归的处理以其为根的子树,
假设该子树包含x个节点,我们考虑以一根从p出发,长度不限的射线,从p的正下方开始按逆时针扫过去,
直到扫过的平面包含x个节点即可停止。此时扫过的平面即为该子树应当处理的平面。
每次处理需要先找到左下角的点,然后对当前平面的所有点进行排序,共需要处理n次,所以复杂度O(n^2*logn)。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
typedef long long ll;
using namespace std;
const int N = ;
const int M = ;
pair<ll,ll>ori;
vector<ll>edg[N];
ll n,m,k;
ll sz[N],ans[N];
struct man{
ll x,y,id;
bool operator < (const man & b) const {
return (x-ori.first)*(b.y-ori.second) - (y-ori.second)*(b.x-ori.first) > ;
}
}p[N];
void dfs1(ll u,ll fa){
sz[u]=;
for(int i=;i<edg[u].size();i++){
ll v=edg[u][i];
if(v==fa)continue;
dfs1(v,u);
sz[u]+=sz[v];
}
}
void dfs2(ll u,ll fa,ll s,ll e){
int pos;
ll x,y;
x=y=1e10;
for(int i=s;i<=e;i++){
if(p[i].x<x||((p[i].x==x)&&p[i].y<y)){
x=p[i].x;y=p[i].y;pos=i;
}
}
ori.first=x;ori.second=y;
swap(p[s],p[pos]);
sort(p+s+,p+e+);
ans[p[s].id]=u;
int cnt=;
for(int i=;i<edg[u].size();i++){
ll v=edg[u][i];
if(v==fa)continue;
dfs2(v,u,s++cnt,s++cnt+sz[v]-);
cnt+=sz[v];
}
}
int main() {
ll T,u,v;
scanf("%lld",&n);
for(int i=;i<n;i++){
scanf("%lld%lld",&u,&v);
edg[u].pb(v);edg[v].pb(u);
}
for(int i=;i<n;i++){
scanf("%lld%lld",&p[i].x,&p[i].y);
p[i].id=i;
}
dfs1(,);
dfs2(,,,n-);
for(int i=;i<n;i++)printf("%lld ",ans[i]);printf("\n");
return ;
}

最新文章

  1. Apache与Nginx对客户端请求的处理机制对比
  2. Match:Cyclic Nacklace(KMP的next数组的高级应用)(HDU 3746)
  3. iOS模拟器多个虚拟机怎么处理
  4. bat 批处理脚本
  5. 图像处理函数详解——im2bw
  6. backbone初次使用及hello world
  7. PHP Strict standards:Declaration of … should be compatible with that of…(转)
  8. 2014/4月金山WPS笔试
  9. [Linked List]Rotate List
  10. mysq Point类型 查询和插入操作:insert和select
  11. 自己动手写CPU 笔记
  12. [Swift]LeetCode315. 计算右侧小于当前元素的个数 | Count of Smaller Numbers After Self
  13. day 12 装饰器
  14. Web版记账本开发记录(七)
  15. 判断是否某App
  16. ubuntu chmod命令的使用
  17. JavaScript学习总结(五)——jQuery插件开发与发布
  18. Linux 网络流量查看 Linux ip traffic monitor
  19. 9-1 A Spy in the Metro uva1025 城市里的间谍 (DP)
  20. install ros-indigo-ecl-build

热门文章

  1. 2018牛客多校第一场 B.Symmetric Matrix
  2. axios超时重发
  3. 【BZOJ 1124】[POI2008] 枪战Maf Tarjan+树dp
  4. Visaul Studio 常用快捷键动画演示
  5. ubuntu下opencv使用cvNamedWindow()和cvShowImage()出错的解决方法
  6. shell正则表达式(1)
  7. RPC-Thrift(一)
  8. [POJ1144][BZOJ2730]tarjan求割点
  9. 01-modal Demo示例程序源代码
  10. PHP HERE DOCUMENT