final graph implementation