Graph algorithms from scratch