Major change in Graph Structure in order to save memory

I have made a lot of changes in many parts of the code, so the code
might have some bugs. It should be tested with several examples.