Graph implementation with NetworkX in Python