| 48 | return ans; |
| 49 | } |
| 50 | public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) { |
| 51 | int rowToposort[] = topoSort(k, rowConditions); |
| 52 | if(rowToposort.length==0){ |
| 53 | return new int[0][0]; |
| 54 | } |
| 55 | int colToposort[] = topoSort(k, colConditions); |
| 56 | if(colToposort.length==0){ |
| 57 | return new int[0][0]; |
| 58 | } |
| 59 | int matrix[][] = new int[k][k]; |
| 60 | for(int i=0;i<k;i++){ |
| 61 | for(int j=0;j<k;j++){ |
| 62 | if(rowToposort[i] == colToposort[j]){ |
| 63 | matrix[i][j] = colToposort[j]; |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | return matrix; |
| 68 | |
| 69 | } |
| 70 | } |