When mark visited, do it immediately after the cell is put into the queue.
If you do it after it is pooled from the queue, it got TLE.
More detailed explanations are in my gitbook.
I am writing in gitbook to summarize my thoughts. Welcome to contact me to discuss. Thanks.