tags::
type:: Leetcode_Solution
in:: Algorithms MOC

Key idea:

the dfs function does the following