KFRIENDS - Friendly Knights
Gurram land is the city of knights and is shaped exactly like a chess board. Some of the cells in this city contains knights. Due to scarcity of grass (Global Warming!), there has been fights between every pair of neighboring knights. knight A is a neighbor of knight B, if A can reach B in exactly one step (see notes for clarity).
To spread peace in the Gurram land, the United Nations has organized a 'Friendship Mela' and wants to distribute friendship neck straps to the knights. Each pair of neighboring knights then exchange neck strap of same color and wear it around their neck, to promote friendship :). To make it more colorful, the UN also wants each knight to have distinct colored neck straps around its neck. The UN is ready to produce any number of straps of a particular color, but can you help them to find out the minimum number of colors to be used.
Notes: A knight in cell (x, y) can move in one step to any of the cells (x+2, y+1), (x+2, y-1), (x+1, y+2), (x+1, y-2), (x-2, y+1), (x-2, y-1), (x-1, y+2), (x-1, y-2) i.e., the normal rule in standard chess.
Input
First line contains T (around 10), the number of test cases. Each test case starts with an integer N (0 <= N <= 10000) the number of knights in the city. Each of the next N lines contains two integers X Y the row and the column number of a knight (1 <= X,Y <= 100). No two knights are on a same cell.
Output
For each test case, print the minimum number of colors needed, in a separate line.
Example
Input: 2 3 1 1 2 3 3 2 4 1 1 2 3 2 1 1 3 Output: 2 1
Case 1 : (1,1) & (2,3) can exchange a Red strap, (1,1) and (3,2) can exchange a Green Strap
Case 2 : (1,1) & (2,3) can exchange a Red strap, (2,1) and (1,3) can exchange a Red Strap
hide comments
creative:
2011-02-07 16:53:00
please make the problem statement clear.
|
|
:D:
2011-01-27 19:04:38
Thank you for the problem, but I'm not sure I understood it correctly. Every knight must exchange a differently coloured strap with every of he's neighbours, right?
|
|
Anil Kishore:
2011-01-27 11:37:59
This is a standard one. If there is a similar problem on SPOJ, I'll move it to Tutorial. Please mention here if you know any other old similar one. |
Added by: | Anil Kishore |
Date: | 2010-12-23 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM32-GCC GAWK MAWK BC C-CLANG NCSHARP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JS-MONKEY JULIA KTLN NIM NODEJS OBJC OBJC-CLANG OCT PICO PROLOG PYPY PYPY3 PY_NBC R RACKET RUST CHICKEN SED SQLITE SWIFT UNLAMBDA VB.NET |
Resource: | Own problem. Used in Jan'2011 IIIT-Hyderabad Internal Contest. |