Graph algorithms implementation.