Various graph algorithms in Python