Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- void dfs(vector<vector<int>>&rooms, int node,vector<bool>&v, int &count){
- if(v[node])return;
- v[node] = true;
- count++;
- for(int i = 0; i<rooms[node].size(); i++){
- int newNode = rooms[node][i];
- dfs(rooms,newNode, v,count);
- }
- }
- bool canVisitAllRooms(vector<vector<int>>& rooms) {
- int n = rooms.size();
- vector<bool>v(n,false);
- int count = 0;
- dfs(rooms, 0, v,count);
- return count==n;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement