Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- IList<IList<int>> graph;
- bool[] marked;
- public bool CanVisitAllRooms(IList<IList<int>> rooms) {
- graph = rooms;
- marked = new bool[rooms.Count];
- dfs(0);
- foreach (bool b in marked) {
- if (!b) return false;
- }
- return true;
- }
- private void dfs(int v) {
- marked[v] = true;
- foreach (int w in graph[v]) {
- if (!marked[w]) {
- dfs(w);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment