{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"题目翻译","value":{"format":"MD","content":"考虑一个二维空间,其中有一组点 $(x_i, y_i)$,对于所有 $i \u003c j$,满足 $x_i \u003c x_j$ 且 $y_i \u003e y_j$。 我们希望将它们全部通过一棵有向树连接起来,该树的边要么向右($x$ 增加),要么向上($y$ 增加)。 \n\n编写一个程序,找到一棵连接所有给定点且边总长度最短的树。\n\n输入:多组数据,每组数据的第一行包含 $1$ 个整数 $n$ $(1 \\le n \\le 1000)$,表示点数。接下来 $n$ 行,第 $i$ 行包含两个整数 $x_i$ 和 $y_i$ $(0 \\le x_i, y_i \\le 10000)$,表示第 $i$ 个点的坐标。\n\n输出:每组数据一行,每行 $1$ 个整数,表示边的总长度。"}},{"title":"题目描述","value":{"format":"MD","content":"Consider a two-dimensional space with a set of points $(x_i, y_i)$ that satisfy $x_i \u003c x_j$ and $y_i \u003e y_j$ for all $i \u003c j$. We want to have them all connected by a directed tree whose edges go toward either right ($x$ positive) or upward ($y$ positive). The figure below shows an example tree.\n\n![](CDN_BASE_URL/5d3158c240c2178a3548cf7d1cc466fd?v\u003d1695124388)\n\nWrite a program that finds a tree connecting all given points with the shortest total length of edges."}},{"title":"输入格式","value":{"format":"MD","content":"The input begins with a line that contains an integer $n$ $(1 \\le n \\le 1000)$, the number of points. Then $n$ lines follow. The $i$-th line contains two integers $x_i$ and $y_i$ $(0 \\le x_i, y_i \\le 10000)$, which give the coordinates of the $i$-th point."}},{"title":"输出格式","value":{"format":"MD","content":"Print the total length of edges in a line."}},{"title":"输入输出样例","value":{"format":"MD","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e5\n1 5\n2 4\n3 3\n4 2\n5 1\n1\n10000 0\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e12\n0\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}