```
class Solution {
public:
int maxVacationDays(vector<vector<int>>& flights, vector<vector<int>>& days) {
int n = flights.size(), k = days[0].size();
vector<int> dp(n, INT_MIN);
dp[0] = 0;
for (int i = 0; i < k; ++i) {
vector<int> prev = dp;
for (int to = 0; to < n; ++to) {
for (int from = 0; from < n; ++from) {
if (from == to || flights[from][to])
dp[to] = max(dp[to], prev[from] + days[to][i]);
}
}
}
int ans = 0;
for (int v : dp)
ans = max(ans, v);
return ans;
}
};
```