Guest User

Untitled

a guest
Jun 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. public class Solution {
  2. IList<IList<int>> graph;
  3. bool[] marked;
  4.  
  5. public bool CanVisitAllRooms(IList<IList<int>> rooms) {
  6. graph = rooms;
  7. marked = new bool[rooms.Count];
  8.  
  9. dfs(0);
  10.  
  11. foreach (bool b in marked) {
  12. if (!b) return false;
  13. }
  14.  
  15. return true;
  16. }
  17.  
  18. private void dfs(int v) {
  19. marked[v] = true;
  20.  
  21. foreach (int w in graph[v]) {
  22. if (!marked[w]) {
  23. dfs(w);
  24. }
  25. }
  26. }
  27. }
Add Comment
Please, Sign In to add comment