/*

It has benn accepted by 39ms. It has a for and a while. it is O(n^2) or O(n) ? I don't not, But it accepted. I love ac.

By the way, My English is not very well. Maybe you don't understand what i say.

It dones't matter. xixi

*/

class Solution

{

public:

int arrayNesting(vector<int>& a)

{

```
int n = a.size();
int sum[20000] = {0};
int maxn = 0;
for (int i = 0; i < n; i++)
{
int j = i;
int cnt = 1;
while (sum[j] == 0)
{
sum[j] = cnt++;
j = a[j];
}
}
for (int i = 0; i < n; i++)
{
maxn = max(sum[i], maxn);
}
return maxn;
}
```

};