class Solution:
    def canVisitAllRooms(self, rooms):
        """
        :type rooms: List[List[int]]
        :rtype: bool
        """
        n=len(rooms)
        isvisited=[0 for i in range(n)]
        stack=[]
        stack.append(0)
        isvisited[0]=1
        while stack:
            temp=stack[-1]
            stack.pop()
            for item in rooms[temp]:
                if isvisited[item]==0:
                    stack.append(item)
                    isvisited[item]=1
        for i in range(n):
            if isvisited[i]==0:
                return False
        return True
s=Solution()
rooms=[[1,3],[3,0,1],[2],[0]]
print(s.canVisitAllRooms(rooms))



