alg3

hopefully working correctly now, it manages to at least output non-empty
graphs without giving an error which is certainly an improvement.