Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须确定无向图是否包含循环。我不应该使用集合!指示。我尝试使用 DFS,但我不知道如何标记访问的节点。
与其将节点标记为已访问,不如构建一个列表来跟踪哪些节点已被访问。您必须将列表传递给 DFS 的递归调用并随时添加。