functionbfsMatrix(matrix, start){const n = matrix.lengthconst seen =newSet([start])const queue =[start]for(let i =0; i < queue.length; i++){const node = queue[i]for(let next =0; next < n; next++){if(matrix[node][next]&&!seen.has(next)){ seen.add(next) queue.push(next)}}}}