Rooks Game
InterviewTime limit2sMemory limit512 MB
Given M rooks on an N x N board, a rook captures another when they share a row or column with nothing between them; find the minimum and maximum number of captures before no captures remain.
- Level
Medium6 of 10
- Topics
- Graph, Union-find, Greedy, Implementation
- Solved
- No attempts yet
Problem
Rooks Game is a single-player game played on an board with rook pieces.
A rook moves any number of unoccupied squares horizontally or vertically. When a rook can attack another rook, it can capture that rook and move to the square the rook occupied. In Rooks Game, white and black are not distinguished, so every rook can capture any other rook.
Initially, there are rooks on the board. In each move, one rook captures another rook. The player repeats captures until no rook can be captured. The game has two goals. One is to minimize the number of captured rooks, and the other is to maximize it.
In this problem, you must find the minimum and maximum values of the number of captured rooks.
Input
The first line contains two integers and , the size of the board and the number of rooks (). Each of the following lines gives the position of one rook. The -th line contains and , meaning the -th rook is in column and row (). No two rooks are in the same place.
Output
Output the minimum and maximum values of the number of captured rooks, separated by a single space.