Very Easy C++ Solution || TOPOSORT
\n\n# Code\n\nclass Solution {\n    vector<int> ts(int V, vector<vector<int>> &adj) {\n        vector<int> indegree(V + 1, 0);\n        vector<int> ans;\n      
\n\n# Code\n```\nclass Solution {\n    vector<int> ts(int V, vector<vector<int>> &adj) {\n        vector<int> indegree(V + 1, 0);\n        vector<int> ans;\n        queue<int> q;\n\n        for (int i = 1; i <= V; ++i) {\n            for (auto it : adj[i]) {\n                indegree[it]++;\n            }\n        }\n\n        for (int i = 1; i <= V; ++i) {\n            if (indegree[i] == 0) {\n                q.push(i);\n            }\n        }\n\n        while (!q.empty()) {\n            int node = q.front();\n            q.pop();\n\n            ans.push_back(node);\n\n            for (auto neigh : adj[node]) {\n                indegree[neigh]--;\n                if (indegree[neigh] == 0) {\n                    q.push(neigh);\n                }\n            }\n        }\n\n        if (ans.size() != V) return {};\n        return ans;\n    }\n\npublic:\n    vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n        vector<vector<int>> rowAdj(k + 1);\n        vector<vector<int>> colAdj(k + 1);\n\n        for (auto it : rowConditions) {\n            int u = it[0];\n            int v = it[1];\n            rowAdj[u].push_back(v);\n        }\n\n        for (auto it : colConditions) {\n            int u = it[0];\n            int v = it[1];\n            colAdj[u].push_back(v);\n        }\n\n        vector<int> row = ts(k, rowAdj);\n        if (row.empty()) return {};\n        vector<int> col = ts(k, colAdj);\n        if (col.empty()) return {};\n\n        vector<int> rowPos(k + 1), colPos(k + 1);\n        for (int i = 0; i < k; ++i) {\n            rowPos[row[i]] = i;\n            colPos[col[i]] = i;\n        }\n\n        vector<vector<int>> ans(k, vector<int>(k, 0));\n        for (int i = 1; i <= k; ++i) {\n            ans[rowPos[i]][colPos[i]] = i;\n        }\n\n        return ans;\n    }\n};\n\n```
['C++']