c++() passed all tests BUT TLE ...
67 / 67 test cases passed, but took too long.\nStatus: Time Limit Exceeded\n\n\nGood day !!! this algo work with each test case separately , but have TLE with a
67 / 67 test cases passed, but took too long.\nStatus: Time Limit Exceeded\n\n\n**Good day !!! this algo work with each test case separately , but have TLE with all testes togeter**\n**What this algo do :**\n**1. I construct graph**\n**2. I try to pass from "child" to "parent" vector of bitsets where I check all numbers for each child and minimal good free number and with parent try to increase minimal value**\n\n**If anyone can help to improve this algo ...**  \n```\n#define N 8192\n#define S 13\nclass Solution {\npublic:\n  vector<int>answer;\n  vector<vector<int>>g;\n  int n;\n  \n  pair<vector<bitset<N>*>, int> dfs(vector<int> &nums, int id, int i){\n    int old_i = i, start = i >> S;\n    vector<bitset<N>*> bst(n, NULL);\n    \n    \n    for(int j = 0; j != g[id].size(); j++){\n      auto[st, t] = dfs(nums, g[id][j], old_i);\n      i = max(i, t);\n      \n      for(int b = start; b != n; b++){\n        if( st[b] == NULL) continue;\n        if( bst[b] == NULL) bst[b] = new bitset<N>;\n        (*bst[b]) |= (*st[b]);\n        \n        delete st[b];\n      }  \n    }\n    \n    int a = (nums[id]-1) >> S;\n    if( bst[a] == NULL ) bst[a] = new bitset<N>;\n    (*bst[a]).set( (nums[id]-1) % N, 1);\n    \n    \n    start = i >> S;\n    if( bst[start] != NULL)\n      if( (*bst[start]).all() ){\n        while(++start != n && bst[start] != NULL && (*bst[start]).all()) delete bst[start];\n        int b = 0;\n        if(start != n && bst[start] != NULL)\n          while( (*bst[start]).test(b) == 1) b++;\n      \n        i = (start<<S) + b;\n      }\n      else{\n        int b = i % N;\n        while( (*bst[start]).test(b) == 1) b++, i++;\n      }\n    \n    \n    answer[id] = i + 1;\n    return {bst, i};\n  }\n  \n  vector<int> smallestMissingValueSubtree(vector<int>& parents, vector<int>& nums) {\n    n = nums.size();\n    g.resize(n), answer.resize(n);\n    \n    for(int i = 0; i != n; i++ )\n      if(parents[i] != -1) g[parents[i]].push_back(i);\n    \n    \n    n = n / N + 1;\n    dfs(nums, 0, 0);\n    \n    return answer;\n  }\n};\n```\n
['C', 'C++']