8443: Delivery Route

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

After several years of record milk production, Farmer John now operates an entire network of N farms (1 <= N <= 100). Farm i is located at position (x_i, y_i) in the 2D plane, distinct from all other farms, with both x_i and y_i being integers.

FJ needs your help planning his daily delivery route to bring supplies to the N farms. Starting from farm 1, he plans to visit the farms sequentially (farm 1, then farm 2, then farm 3, etc.), finally returning to farm 1 after visiting farm N. It tames FJ one minute to make a single step either north, south, east, or west. Furthermore, FJ wants to visit each farm exactly once during his entire journey (except farm 1, which he visits twice of course).

Please help FJ determine the minimum amount of time it will take him to complete his entire delivery route.

FJ有N (1 <= N <= 100)个农场,每个农场具有独立的整数坐标(x_i, y_i)。他需要一个物资配送路线,从第1个农场出发,依次经过农场1,农场2,农场3…,最后从农场N回到农场1.

FJ每次只能朝东南西北四个方向行走,没行走一个单位长度需要1分钟,除了农场1,其他农场能且仅能到达一次。

请计算FJ的最小时间花费。

输入格式

* Line 1: The number of farms, N.

* Lines 2..1+N: Line i+1 contains two space-separated integers, x_i and y_i (1 <= x_i, y_i <= 1,000,000).

第一行包含整数 N。



接下来 N 行,每行包含两个整数 xi 和 yi,表示一个农场的位置坐标。

输出格式

输出约翰走完整个运送路线所需的最短时间。



如果不存在可行的运送路线,则输出 −1。

输入样例 复制

4
2 2
2 4
2 1
1 3

输出样例 复制

12

数据范围与提示

约翰可以在 12 分钟内完成交货路线:



从农场 1 到农场 2 需要 2 分钟,从农场 2 到农场 3(需避开农场 1)需要 5 分钟,从农场 3 到农场 4 需要 3 分钟,返回农场 1 需要 2 分钟。

数据范围

1≤N≤100,

1≤xi,yi≤106