All submissions for this problem are available.
Read problems statements in Mandarin Chinese here
City of Byteland can be described as a 2D grid of cells. Each cell may or may not contain a demon. You are given the list of cells that contain demons.
In a single Kamehameha attack, Goku can kill all the demons stading in a row or in a column. But using Kamehameha drains Goku's power. You are to tell the minimum number of Kamehameha attacks that will be required by Goku to destroy all the demons.
The first line contains T the number of test cases. The first line of each test case contains N the number of cells where enemies are present. The following N lines contain two integers X and Y each describing the index of the cell in which the demon is present.
For each case print the minimum number of attacks that are needed to kill all the monsters.
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 1000
- 1 ≤ X, Y ≤ 109
Input 1 3 0 0 1 0 0 1 Output 2
|Tags||bipartite, easy-medium, kaushik_iska, matching, oct13|
|Time Limit:||2 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.5, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.