Gary has a board of size NxM. Each cell in the board is a coloured dot. There exist only 26 colours denoted by uppercase Latin characters (i.e. A,B,...,Z). Now Gary is getting bored and wants to play a game. The key of this game is to find a cycle that contain dots of same colour. Formally, we call a sequence of dots d1,?d2,?...,?dk a cycle if and only if it meets the following condition:
- These k dots are different: if i?≠?j then di is different from dj.
- k is at least 4.
- All dots belong to the same colour.
- For all 1?≤?i?≤?k?-?1: di and di?+?1 are adjacent. Also, dk and d1 should also be adjacent. Cells x and y are called adjacent if they share an edge.
Since Gary is colour blind, he wants your help. Your task is to determine if there exists a cycle on the board
question from:
https://stackoverflow.com/questions/65914744/im-not-getting-what-the-problem-wants-to-say-by-line-that-dk-and-d1-should-al 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…