refactored graph problems