c++ | easy to undersatand | step by step
```\nclass Solution {\n    vector top_sorting(vector> con, int k) {\n        vector indegree(k+1, 0);\n        vector> graph(k+1);\n        for(auto &it: con) {
```\nclass Solution {\n    vector<int> top_sorting(vector<vector<int>> con, int k) {\n        vector<int> indegree(k+1, 0);\n        vector<vector<int>> graph(k+1);\n        for(auto &it: con) {\n            indegree[it[1]] += 1;\n            graph[it[0]].push_back(it[1]);\n        }\n        \n        vector<int> ans;\n        queue<int> q;\n        for(int i = 1; i <= k; i++) {\n            if(indegree[i] == 0)\n                q.push(i);\n        }\n        \n        while(!q.empty()) {\n            int u = q.front();\n            q.pop();\n            ans.push_back(u);\n            for(int v: graph[u]) {\n                indegree[v]--;\n                if(indegree[v] == 0) \n                    q.push(v);\n            }\n        }\n        \n        return ans;\n    }\n    \npublic:\n    vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowC, vector<vector<int>>& colC) {\n        vector<int> rowOrder = top_sorting(rowC, k);\n        vector<int> colOrder = top_sorting(colC, k);\n        \n        // check cycle\n        if(rowOrder.size() != k || colOrder.size() != k)\n            return {};        \n\t\t\t\n        // row index and col index of i\n        vector<int> r(k+1), c(k+1);\n        for(int i = 0; i < k; i++) {\n            r[rowOrder[i]] = i;\n            c[colOrder[i]] = i;\n        }\n        \n        vector<vector<int>> ans(k, vector<int>(k, 0));\n        for(int i = 1; i <= k; i++) \n            ans[r[i]][c[i]] = i;\n        \n        return ans;\n    }\n};
[]