#d2496. 魔法阵传送
魔法阵传送
Magic Array Teleport
Problem Description
There are integer points (both coordinates are integers) on the plane, called "magic arrays".
A teleport works as follows:
- You start from some magic array.
- You may choose a magic , where are integers. Applying this magic once to any integer point moves it to .
- Throughout the whole teleport from the starting magic array to the next magic array, you may use only one kind of magic, but you may use it any number of times.
Find the minimum number of magics you must master so that, starting from any magic array, you can directly teleport to any other magic array without passing through another magic array in between.
Input Format
The first line contains an integer .
The next lines each contain two integers , the coordinates of the -th magic array.
Output Format
Output one integer: the answer.
Sample Input 1
3
1 1
4 5
1 4
Sample Output 1
6
Sample Explanation
The directions that need to be covered are: from to and ; from to and ; from to and .
Note that you cannot reach from by combining , because a single teleport may use only one kind of magic.
Of course, you may also learn the magic , in which case going from to requires using this magic times.
Sample Input 2
3
1 1
2 2
1000000000 1000000000
Sample Output 2
2
Constraints
- , and all coordinates are pairwise distinct.