Graph Theory implementation in Python