fix: construct sparse matrix using topological sort order