The loop one transfer short
transcript
Find the shortest loop of transfers. Search from the account. Count the loop length.
Take two accounts with transfers both ways. The loop is zero, one, zero. That is two transfers. The bug returns one.
The distance of u counts steps from the start. The transfer back is one more. So add one.
The start has distance zero. A self-transfer is one more. So the loop has length one.
With the plus one, all one thousand inputs agree. Without it, the first seed fails. It returns one instead of two.
Test two accounts first. Test one self-transfer. Test a graph with no loop.
Five hundred accounts and two thousand transfers. A search from each costs about a million steps. That is fast, so keep the plain search.
Write a slow twin that follows walks of every length. It stops at the first length that returns. Compare both on random tiny graphs.
Distance counts steps. The return is one more. Full breakdown in the lecture.