SP8786 DOMINO1 - The Longest Chain of Domino Tiles
Description
You are given N domino tiles. Each tile is made of some number of squares (not necessarily two), and each square is coloured either white or black (we use the Croatian letters: B for white and C for black).
Find the longest chain that can be made of these tiles. Each tile can be used at most once and cannot be rotated (for example, BC cannot become CB). The chain is made by a common rule: in adjacent tiles, touching squares must be of the same colour.
Input Format
\[N
in the next N lines:
\[a string of size between 1 and 100, representing the domino\]
Output Format
The length of the longest chain.