TopCoder

Thumb giphy  1
實中34th的一個人
要吃巧克力嗎??

User's AC Ratio

89.3% (25/28)

Submission's AC Ratio

59.4% (41/69)

Description

在一個N x N的平面上 (1 <= N <= 500),有K塊隕石 (1 <= K <= 10,000),分別在一些格子中。卡恩想要用他的強者光束把所有隕石給清除,每一次使用強者光束都可以把某一整行或一整列的隕石給消滅。但由於卡恩對演算法的狂熱,他除了要清除所有隕石,還希望使用最少次的強者光束。
今給出所有隕石的位置,試問最少要使用幾次強者光束,才能把所有的隕石消滅?

(原文)
Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conveniently located at the lattice points of the grid.
Fortunately, Bessie has a powerful weapon that can vaporize all the asteroids in any given row or column of the grid with a single shot. This weapon is quite expensive, so she wishes to use it sparingly.
Given the location of all the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate all of the asteroids.

Input Format

第一行有兩個整數N和K,分別代表平面的邊長(有幾個格子)以及有幾塊隕石。
接下來K行,每行有兩個數R和C,代表一塊隕石的位置(第幾列,第幾行)。

(原文)
* Line 1: Two integers N and K, separated by a single space.
* Lines 2..K+1: Each line contains two space-separated integers R and C (1 <= R, C <= N) denoting the row and column coordinates of an asteroid, respectively.

Output Format

請輸出一個數字,代表最少要使用幾次強者光束?

(原文)
* Line 1: The integer representing the minimum number of times Bessie must shoot.

Sample Input

3 4
1 1
1 3
2 2
3 2

Sample Output

2

Hints

卡恩好威!

(Tmt補註:下次要改成球主啦= =+)

Problem Source

原TIOJ1089 / USACO Gold Demo, 2005 Nov。Translation/Problem Setter: kelvin。

Subtasks

For Testdata: 0 ~ 0, Score: 8
For Testdata: 1 ~ 1, Score: 8
For Testdata: 2 ~ 2, Score: 8
For Testdata: 3 ~ 3, Score: 8
For Testdata: 4 ~ 4, Score: 8
For Testdata: 5 ~ 5, Score: 8
For Testdata: 6 ~ 6, Score: 8
For Testdata: 7 ~ 7, Score: 8
For Testdata: 8 ~ 8, Score: 8
For Testdata: 9 ~ 9, Score: 8
For Testdata: 10 ~ 10, Score: 8
For Testdata: 11 ~ 11, Score: 12
No. Time Limit (ms) Memory Limit (KiB) Output Limit (KiB)
0 1000 65536 65536
1 1000 65536 65536
2 1000 65536 65536
3 1000 65536 65536
4 1000 65536 65536
5 1000 65536 65536
6 1000 65536 65536
7 1000 65536 65536
8 1000 65536 65536
9 1000 65536 65536
10 1000 65536 65536
11 1000 65536 65536