Implement networkx algorithm