C++ in a graph thought T:O(n)/S:O(1)
\n/*\n    Can we apply graph?\n    T:O(n)/S:O(n)\n*/\nclass Solution {\npublic:\n    int reinitializePermutation(int n) {\n        vector<int> graph(n,0);\n    
```\n/*\n    Can we apply graph?\n    T:O(n)/S:O(n)\n*/\nclass Solution {\npublic:\n    int reinitializePermutation(int n) {\n        vector<int> graph(n,0);\n        for (int i=0; i<n; ++i) \n            graph[i]=i%2==0 ? i/2 : (i-1)/2+n/2;\n        int cur=graph[1], ans=1;\n        while (cur!=1) {cur=graph[cur]; ans++;}\n        return ans;\n    }\n};\n```
[]