kinda of flood fill, memorized search (dp) in dfs