Refactor graph representation conversion

All conversions are refactor to use global variables.
Some of the programs are modified for multigraphs.
Minor optimizations.