queue<vector<int>>gave tle while queue<pair<int,int>> beats 100%
\n# Complexity\n- Time complexity:\n- O(n^2 *2^n)\n Add your time complexity here, e.g. O(n) \n\nwhen I used queue> i got tle but when i used queue of pair my c
\n# Complexity\n- Time complexity:\n- O(n^2 *2^n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\nwhen I used queue<vector<int>> i got tle but when i used queue of pair my code beats 100% if you know please explain\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\n    void calc(int kx,int ky,vector<vector<int>>&v)\n    {\n        queue<pair<int,int>>q;\n        q.push({kx,ky});\n        int dx[]={1,-1,2,-2,1,-1,2,-2};\n        int dy[]={2,-2,1,-1,-2,2,-1,1};\n        while(q.size()>0)\n        {\n            pair<int,int> p=q.front();\n            q.pop();\n            for(int j=0;j<8;j++)\n            {\n                int nx=p.first+dx[j];\n                int ny=p.second+dy[j];\n                if(nx>=0 && ny>=0 && nx<50 && ny<50 && v[nx][ny]==-1)\n                {\n                    v[nx][ny]=v[p.first][p.second]+1;\n                    q.push({nx,ny});\n                }\n            }\n        }\n    }\n    int find(int mask,int curPos,int move,vector<vector<int>>&dp,vector<vector<int>>&pos,int n,vector<vector<vector<int>>>&moves)\n    {\n        if(mask==0) return 0;\n        if(dp[mask][curPos]!=-1) return dp[mask][curPos];\n        int ans=0;\n        if(move==0) ans=1e9+7;\n        for(int j=0;j<n;j++)\n        {\n            if((mask&(1<<j)))\n            {\n                if(move==1)\n                ans=max(ans,find(mask^(1<<j),j,0,dp,pos,n,moves)+moves[curPos][pos[j][0]][pos[j][1]]);\n                else \n                ans=min(ans,find(mask^(1<<j),j,1,dp,pos,n,moves)+moves[curPos][pos[j][0]][pos[j][1]]);\n            }\n        }\n        return dp[mask][curPos]=ans;\n    }\npublic:\n    int maxMoves(int kx, int ky, vector<vector<int>>& v) {\n        int n=v.size();\n        vector<vector<vector<int>>>moves(n,vector<vector<int>>(50,vector<int>(50,-1)));\n        for(int i=0;i<n;i++)\n        {\n            moves[i][v[i][0]][v[i][1]]=0;\n            calc(v[i][0],v[i][1],moves[i]);\n        }\n        vector<vector<int>>mat(50,vector<int>(50,-1));\n        mat[kx][ky]=0;\n        calc(kx,ky,mat);\n\n        int m=1<<n;\n        vector<vector<int>>dp(m,vector<int>(n,-1));\n        int ans=0;\n        m-=1;\n        for(int i=0;i<n;i++)\n        {\n            ans=max(ans,mat[v[i][0]][v[i][1]]+find(m^(1<<i),i,0,dp,v,n,moves));\n        }\n        return ans;\n    }\n};\n```
['C++']