E - Paint Tree

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 ≤ nui ≠ 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.

Example

Input
31 32 30 01 12 0
Output
1 3 2
Input
41 22 31 4-1 -23 5-3 32 0
Output
4 2 1 3

Note

The possible solutions for the sample are given below.

 

题目意思就是,给你一棵已经定型的无根树,然后在二维屏幕上给出几个坐标,要求将树的每一个节点对应到二维平面上的每一个点上,要求形成的是一棵正常的树.

这题完全没思路,只知道肯定是排序+DFS,然而,就是没有想的更深一点——极角排序+分治.

我们每次递归分治的的时候,标记的总是一段区间,这个区间是有一定顺序的,他按照基准点极角排序.为什么极角排序就一定对呢?

因为每一次,你找的相当于在凸多边形上这个点的下几个点,不会穿越其他线段,这段区间也会被覆盖满(极角排序的性质很适用).最后输出就好了,效率应该是n^nlogn的。

 #include<cstdio>
 #include<cstring>
 #include<algorithm>
 #define LL long long
 using namespace std;
 ,maxe=;
 int size[maxn],fa[maxn];
 int n,tot,nxt[maxe],son[maxe],lnk[maxn],ans[maxn];
 bool vis[maxn];
 struct point{int x,y,id;}a[maxn],mainp;
 point operator - (point p,point q){point ret; ret.x=p.x-q.x,ret.y=p.y-q.y; return ret;}
 LL cross(point p,point q){return (LL)p.x*q.y-(LL)q.x*p.y;}
 bool cmp1(point u,point v){return u.x!=v.x?u.x<v.x:u.y<v.y;}
 ;}
 int read(){
     ,f=; char ch=getchar();
     '){if (ch=='-') f=-f; ch=getchar();}
     +ch-',ch=getchar();
     return x*f;
 }
 void add(int x,int y){nxt[++tot]=lnk[x],son[tot]=y,lnk[x]=tot;}
 void DFS(int x){
     vis[x]=,size[x]=;
     for (int j=lnk[x]; j; j=nxt[j]) if (!vis[son[j]]){
         DFS(son[j]); size[x]+=size[son[j]];
     }
 }
 void DFS(int x,int fa,int L,int R){
     sort(a+L,a++R,cmp1);
     ans[a[L].id]=x,mainp.x=a[L].x,mainp.y=a[L].y;
     sort(a++L,a++R,cmp2);
     int now=L;
     for (int j=lnk[x]; j; j=nxt[j]) if (son[j]!=fa){
         DFS(son[j],x,now+,now+size[son[j]]),now+=size[son[j]];
     }
 }
 int main(){
     n=read(),tot=;
     ; i<n; i++){int x=read(),y=read(); add(x,y),add(y,x);}
     memset(vis,,,);
     ; i<=n; i++) a[i].x=read(),a[i].y=read(),a[i].id=i;
     DFS(,,,n);
     ; i<=n; i++) printf("%d ",ans[i]);
     ;
 }

[CodeForces - 197E] E - Paint Tree的更多相关文章

  1. Codeforces 196 C. Paint Tree

    分治.选最左上的点分给根.剩下的极角排序后递归 C. Paint Tree time limit per test 2 seconds memory limit per test 256 megaby ...

  2. Codeforces Round #124 (Div. 1) C. Paint Tree(极角排序)

    C. Paint Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  3. Codeforces 196C Paint Tree(贪心+极角排序)

    题目链接 Paint Tree 给你一棵n个点的树和n个直角坐标系上的点,现在要把树上的n个点映射到直角坐标系的n个点中,要求是除了在顶点处不能有线段的相交. 我们先选一个在直角坐标系中的最左下角的点 ...

  4. Codeforces 461B Appleman and Tree(木dp)

    题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每一个节点的父亲节点,以及每一个点的颜色(0表示白色,1表示黑色),切断这棵树的k ...

  5. Codeforces 1129 E.Legendary Tree

    Codeforces 1129 E.Legendary Tree 解题思路: 这题好厉害,我来复读一下官方题解,顺便补充几句. 首先,可以通过询问 \(n-1​\) 次 \((S=\{1\},T=\{ ...

  6. Codeforces 280C Game on tree【概率DP】

    Codeforces 280C Game on tree LINK 题目大意:给你一棵树,1号节点是根,每次等概率选择没有被染黑的一个节点染黑其所有子树中的节点,问染黑所有节点的期望次数 #inclu ...

  7. Codeforces A. Game on Tree(期望dfs)

    题目描述: Game on Tree time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #781(C. Tree Infection)

    Codeforces Round #781 C. Tree Infection time limit per test 1 second memory limit per test 256 megab ...

  9. Codeforces 734E. Anton and Tree 搜索

    E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...

随机推荐

  1. 理解git的分支原理,更好地使用git

    文章内容转载于git-scm. 部分内容涉嫌枯燥 一.git分支概念 几乎每一种版本控制系统都以某种形式支持分支.使用分支意味着你可以从开发主线上分离开来,然后在不影响主线的同时继续工作.在很多版本控 ...

  2. 异步加载script,提高前端性能(defer和async属性的区别)

    一.异步加载script的好处 为了加快首屏响应速度,前端会采用代码切割.按需加载等方式优化性能.异步加载script也是一种前端优化的手段. 就好比如果我的页面其中一个功能需要打开地图,但是地图的j ...

  3. Integer的最大值

    来自:https://blog.csdn.net/qq_33611068/article/details/77369050 有这样一道题: 编程测试,遍历 0 到 int所能表示最大的正数,将消耗的时 ...

  4. Pycharm设置去除显示的波浪线

    1.选择文件选择file—Settings,如下图打开setting对话框 2.选择Editur—Color Scheme—General选项,然后选择右边对话框中的Errors and Warnin ...

  5. isnull和sum的关系

    这是我刚刚写存储过程的时候意识到的一个问题!!! 先问大家这样一个问题,print 100+null  等于多少? 在一组数据统计的过程中,只要使用到sum函数,就必须使用isnull函数包含起来,因 ...

  6. [原][粒子特效][spark]深入浅出osgSpark

    背景: 目前我使用的spark粒子特效库是2.0 这个库好像是原来鬼火引擎的一部分,需要从github上找 现在我要将其使用到我自己开发的基于osgearth开的三维地图引擎中 步骤: 1.编译spa ...

  7. 插件写法之脚本运行环境,mac和window检测

    (function(root, factroy){   /* * 在这里进行对脚本运行环境的检测判断 * 浏览器中 有window对象 * node.js服务器端 有Global对象 * * IE11 ...

  8. 远程Service的显示 / 隐式启动

    在进程间通信时,常会设计开启远程 Service 的情况.开启远程 Service 的方式有两种,一种时显示开启,一种是隐式开启.下面分别来看: 一.隐式开启 服务端:Service 所在 Andro ...

  9. Centos 7系统挂载NTFS格式移动硬盘

    有些时候做大数据量迁移时,为了快速迁移大数据,有可能在Linux服务器上临时挂载NTFS格式的移动硬盘, 一般情况下,linux是识别不了NTFS格式移动硬盘的(需要重编译Linux核心才能,加挂NT ...

  10. 力扣(LeetCode)1002. 查找常用字符

    给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表.例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 ...