C++ dp and prefix sum.
\nclass Solution {\npublic:\n    typedef long long ll;\n    ll big = 1e9 + 7;\n    int firstDayBeenInAllRooms(vector<int>& nextVisit) {\n        int n = nextVis
```\nclass Solution {\npublic:\n    typedef long long ll;\n    ll big = 1e9 + 7;\n    int firstDayBeenInAllRooms(vector<int>& nextVisit) {\n        int n = nextVisit.size();\n\t\t// dp[i] means the steps it takes from i (first reaching i) to i+1;\n        vector<ll> dp(n, 0);\n\t\t// sum[i] = dp[0] + dp[1] ... + dp[i-1];\n        vector<ll> sum(n, 0);\n        dp[0] = 2;\n        sum[1] = 2;\n        for(int i=1; i<n-1; ++i) {\n            int prev = nextVisit[i];\n            dp[i] = (2 + sum[i] - sum[prev] + big) % big;\n            sum[i+1] = (sum[i] + dp[i]) % big;\n        }\n        \n        return sum[n-1];\n    }\n};\n```
[]