topological sort
Topological Sort (위상 정렬)
/* 이 알고리즘(위상정렬)이 사용된 백준 문제 -> BOJ/Graph/2252.js -> BOJ/Graph/1516.js -> 줄 세우기 */ const testInput = [ [4, 2], [3, 1] ]; const N = 4; // 노드의 개수 function topological_sort() { let graph = Array.from({length: N + 1}, () => []); let indegrees = Array(N + 1).fill(0); let queue = []; let result = []; for(const [from, to] of testInput) { // from 노드와 이어져 있는 to 노드 추가 graph[from].push(to); // to 노드와 이어져 있는 ..