Simulation (DP Alternative)
This one was very hard for me. I tried to simulate and memoise cycles, but it failed stronger test cases (TLE).\n\n\nI could not see a DP transition, so I kept 
This one was very hard for me. I tried to simulate and memoise cycles, but it failed stronger test cases (TLE).\n\n\nI could not see a DP transition, so I kept on working on the simulation. Perhaps it would be easier to understand.\n\n1. When we visit a `room` for the first time on day `d1`, we store that day in `first[room]`.\n\t- Since the first visit is an odd visit, we go to the room specified in `nextVisit`.\n\t- But before we go, we remember the current room in `prev`.\n2. When we visit the same `room` again on day `d2`, that means that we have a cycle. \n\t- The length of the cycle is `d2 - first[room]`. \n\t- After we add those days, we will be in the room after `prev` (we will visit `prev` one day before that, and it will be an even visit).\n\nI needed to whiteboard this to figure out the solution; here is an illustration of cycles and transitions for test case `[0,0,0,1,0,2]`.\n\n![image](https://assets.leetcode.com/users/images/b254581a-adf6-4373-a794-96b399ce1947_1631258725.6442018.png)\n\n**C++**\n```cpp\nint firstDayBeenInAllRooms(vector<int>& nextVisit) {\n    long long n = nextVisit.size(), total = 0, day = 0, room = 0, prev = 0, mod = 1000000007;\n    vector<long long> visited(n), first(n, 0);\n    while (total < n) {\n        if (++visited[room] == 1) {\n            ++total;\n            first[room] = day++;\n            prev = room;\n            room = nextVisit[room]; \n        }\n        else {\n            day = (mod + day + day - first[room]) % mod;\n            room = (prev + 1) % n;\n        }\n    }\n    return day - 1;\n}   \n```
[]