#DSU0000050. Bảng hóa học (Chemical Table)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bảng hóa học (Chemical Table)
Chemical Table
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A laboratory has a table with rows and columns. Some cells already contain samples; the remaining cells are empty. The initially occupied cells are specified by their row and column coordinates.
The laboratory can create a new sample for free as follows: choose an axis-aligned rectangle whose four corners are cells of the table. If samples already occupy three corners, a sample can be placed at the fourth corner. Existing samples remain, and newly created samples may be used in later operations.
The laboratory can also buy a sample and place it in any empty cell, at a unit cost. Find the minimum number of samples that must be bought so that eventually every cell contains a sample.
Input
The first line contains . Each of the next lines has row and column of an initially known cell.
Output
Print the minimum number of purchases.
Subtasks
- Subtask 1 (20 points): , ; ; , ; initially occupied cells are distinct.
- Subtask 2 (30 points): , ; ; , ; initially occupied cells are distinct.
- Subtask 3 (50 points): , ; ; , ; initially occupied cells are distinct.
Examples
Input
2 2 3
1 2
2 2
2 1
Output
0
Explanation
The three known cells are three corners of a 2-by-2 rectangle; the missing corner (1,1) can be created without any purchase, so the answer is 0.