Implement graph algorithms.