A C Solution
Code\n\n#define MAX_K 400\n\nstruct node {\n    int val;\n    struct node* next;\n};\n\nstruct graph {\n    struct node* head[MAX_K + 1];\n    int inDegree[MAX_
# Code\n```\n#define MAX_K 400\n\nstruct node {\n    int val;\n    struct node* next;\n};\n\nstruct graph {\n    struct node* head[MAX_K + 1];\n    int inDegree[MAX_K + 1];\n};\n\nvoid addEdge(struct graph* graph, int from, int to) {\n    struct node* new = malloc(sizeof(struct node));\n    new->val = to;\n    new->next = graph->head[from];\n    graph->head[from] = new;\n    graph->inDegree[to]++;\n}\n\nbool topologicalSort(int k, struct graph* graph, int* order) {\n    int queue[MAX_K + 1];\n    int front = 0, rear = 0;\n    int orderIdx = 0;\n    \n    for(int i = 1; i <= k; i++) {\n        if(graph->inDegree[i] == 0) {\n            queue[rear++] = i;\n        }\n    } \n    while(front < rear) {\n        int node = queue[front++];\n        order[orderIdx++] = node;\n        \n        struct node* current = graph->head[node];\n        while (current) {\n            graph->inDegree[current->val]--;\n            if (graph->inDegree[current->val] == 0) {\n                queue[rear++] = current->val;\n            }\n            current = current->next;\n        }\n    }\n    \n    return orderIdx == k;\n}\n\nint** buildMatrix(int k, int** rowConditions, int rowConditionsSize, int* rowConditionsColSize, int** colConditions, int colConditionsSize, int* colConditionsColSize, int* returnSize, int** returnColumnSizes) {\n    struct graph rowGraph = {.head = {NULL}, .inDegree = {0}};\n    struct graph colGraph = {.head = {NULL}, .inDegree = {0}};\n    int rowOrder[MAX_K + 1];\n    int colOrder[MAX_K + 1];\n    \n    for(int i = 0; i < rowConditionsSize; i++) {\n        addEdge(&rowGraph, rowConditions[i][0], rowConditions[i][1]);\n    }\n    for(int i = 0; i < colConditionsSize; i++) {\n        addEdge(&colGraph, colConditions[i][0], colConditions[i][1]);\n    }   \n    if(!topologicalSort(k, &rowGraph, rowOrder) || !topologicalSort(k, &colGraph, colOrder)) {\n        *returnSize = 0;\n        return rowConditions;\n    }\n\n    int** ret = malloc(k * sizeof(int*));\n    *returnColumnSizes = malloc(k * sizeof(int));\n    *returnSize = k;\n\n    for(int i = 0; i < k; i++) {\n        (*returnColumnSizes)[i] = k;\n        ret[i] = calloc(k, sizeof(int));\n    }\n    \n    int rowPos[MAX_K + 1];\n    int colPos[MAX_K + 1];\n    \n    for (int i = 0; i < k; i++) {\n        rowPos[rowOrder[i]] = colPos[colOrder[i]] = i;\n    }\n    for (int num = 1; num <= k; num++) {\n        ret[rowPos[num]][colPos[num]] = num;\n    }\n    \n    return ret;\n}\n```
['C']