题目描述链接:https://leetcode-cn.com/problems/keys-and-rooms/
LeetCode C++ 解题代码:
class Solution { public: int vis[1005]; bool canVisitAllRooms(vector<vector<int>>& rooms) { dfs(rooms,0); for(int i=0;i<rooms.size();i++){ if(vis[i]==0){ return false; } } return true; } void dfs(vector<vector<int>>& rooms,int i){ vis[i]=1; for(int j=0;j<rooms[i].size();j++){ if(vis[rooms[i][j]]==0) dfs(rooms,rooms[i][j]); } } };