#P3913. Attacked Chessboard Cells
Attacked Chessboard Cells
Attacked Chessboard Cells
Given an (N \times N) international chessboard with (K) rooks, where the (i)-th rook is located at row (R_i) and column (C_i), determine the number of cells that are attacked by at least one rook. A rook can attack any cell in the same row or the same column.
Note: The indices for rows and columns are 1-indexed.
inputFormat
The input consists of multiple lines. The first line contains two integers (N) and (K) (where (1 \leq N \leq 10^5) and (0 \leq K \leq N \times N)). Each of the following (K) lines contains two integers (R_i) and (C_i) indicating the row and column position of the (i)-th rook.
outputFormat
Output a single integer: the number of cells that are attacked by at least one rook. A cell is considered attacked if its row or column contains at least one rook.
sample
8 2
1 3
5 6
22
</p>