For p1 a BFS algorithm is fast enough. For pt 2, for the third day in a row, it did not work. I caved in and used recursion and memoisation for DFS instead, instantly fast as lightning. I finished by making the pt 2 code compatible with pt 1.