iterative approach, reducing max from graph each time