[C++] Disjoint Set Union solution
Our task is to find the maximum cycle in the permutation. Since all cycles are disjoint we should find the size of the largest set in DSU.\n\n\nstruct DSU {\n  
Our task is to find the maximum cycle in the permutation. Since all cycles are disjoint we should find the size of the largest set in DSU.\n\n```\nstruct DSU {\n  vector<int> parent;\n  vector<int> sizes;\n\n  DSU(int sz): parent(sz), sizes(sz) {\n    for (int i = 0; i < sz; ++i) {\n      parent[i] = i;\n      sizes[i] = 1;\n    }\n  }\n\n  int find(int x) {\n    if (x == parent[x]) {\n      return x;\n    }\n    return parent[x] = find(parent[x]);\n  }\n\n  void join(int a, int b) {\n    a = find(a);\n    b = find(b);\n\n    if (a != b) {\n      if (sizes[a] < sizes[b]) {\n        swap(a, b);\n      }\n      parent[b] = a;\n      sizes[a] += sizes[b];\n    }\n  }\n};\n\nint arrayNesting(vector<int>& nums) {\n  DSU d(nums.size());\n\n  for (int i = 0; i < nums.size(); ++i) {\n    d.join(i, nums[i]);\n  }\n\n  return *max_element(d.sizes.begin(), d.sizes.end());\n}\n```
[]