use range based for loops to traverse graphs