Output formatting, and implemented greedy algorithm in place of
brute-force DFS