CF277E.Binary Tree on Plane
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A root tree is a directed acyclic graph that contains one node (root), from which there is exactly one path to any other node.
A root tree is binary if each node has at most two outgoing arcs.
When a binary tree is painted on the plane, all arcs should be directed from top to bottom. That is, each arc going from u to v must meet the condition y__u > y__v.
You've been given the coordinates of all tree nodes. Your task is to connect these nodes by arcs so as to get the binary root tree and make the total length of the arcs minimum. All arcs of the built tree must be directed from top to bottom.
根树是一种有向无环图,其中存在一个节点(称为根节点),从该节点出发到任意其他节点都恰好存在一条路径。
若一棵根树的每个节点至多有两个向外的有向边,则称其为二叉根树。
当将一棵二叉树绘制在平面上时,所有有向边必须自上而下指向。即,对任意一条从节点 u 指向节点 v 的有向边,必须满足 yu>yv。
你已获得树中所有节点的坐标。你的任务是用有向边连接这些节点,构造一棵二叉根树,并使所有有向边的总长度最小。所构造树中的所有有向边均须满足自上而下的方向要求。
输入格式
The first line contains a single integer n (2 ≤ n ≤ 400) — the number of nodes in the tree. Then follow n lines, two integers per line: x__i, y__i (|x__i|, |y__i| ≤ 103) — coordinates of the nodes. It is guaranteed that all points are distinct.
第一行包含一个整数 n(2≤n≤400)——树中节点的数量。接下来是 n 行,每行两个整数:xi,yi(∣xi∣,∣yi∣≤103)——各节点的坐标。保证所有点互不相同。
输出格式
If it is impossible to build a binary root tree on the given points, print "-1". Otherwise, print a single real number — the total length of the arcs in the minimum binary tree. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.
如果无法在给定的点上构建二叉根树,则输出 -1。否则,输出一个实数——最小二叉树中所有弧的总长度。若答案的绝对误差或相对误差不超过 10−6,则视为正确。
输入输出样例
输入#1
3 0 0 1 0 2 1
输出#1
3.650281539872885
输入#2
4 0 0 1 0 2 1 2 0
输出#2
-1
输入解题思路,AI测评打分。不知道怎么写?