{"text":"int tsp(vector<vector<int>> &cost) {\r\n\r\n    // Number of nodes\r\n    int numNodes = cost.size();\r\n    vector<int> nodes;\r\n\r\n    // Initialize the nodes excluding the fixed \r\n   // starting point (node 0)\r\n    for (int i = 1; i < numNodes; i++)\r\n        nodes.push_back(i);\r\n\r\n    int minCost = INT_MAX;\r\n\r\n    // Generate all permutations of the remaining nodes\r\n    do {\r\n        int currCost = 0;\r\n\r\n        // Start from node 0\r\n        int currNode = 0;\r\n\r\n        // Calculate the cost of the current permutation\r\n        for (int i = 0; i < nodes.size(); i++) {\r\n            currCost += cost[currNode][nodes[i]];\r\n            currNode = nodes[i];\r\n        }\r\n\r\n        // Add the cost to return to the starting node\r\n        currCost += cost[currNode][0];\r\n\r\n        // Update the minimum cost if the current cost \r\n      // is lower\r\n        minCost = min(minCost, currCost);\r\n\r\n    } while (next_permutation(nodes.begin(), nodes.end()));\r\n\r\n    return minCost;\r\n}\r\n"}
