solution of the catvsdog puzzle using the networkx library