https://programmers.co.kr/learn/courses/30/lessons/12978
function solution(N, road, K) {
let arr = Array(N+1).fill(Infinity);
let adj = Array.from(Array(N+1), () => Array());
for(let [a, b, c] of road) {
adj[a].push({ to: b, time: c });
adj[b].push({ to: a, time: c });
}
let check = [{ to: 1, time: 0 }];
arr[1] = 0;
while(check.length) {
let { to, time } = check.pop();
adj[to].forEach(next => {
// next.to: 이동할 마을 / to: 현재 마을 / next.time: 이동할 마을까지 걸리는 시간
if(arr[next.to] > arr[to] + next.time) {
arr[next.to] = arr[to] + next.time;
check.push(next);
}
});
}
return arr.filter((time) => time <= K).length;
}
똑똑한 사람들,,,,,🥺
부지런히 공부하자 🔥
참고
[프로그래머스] 레벨3 (level3) 배달
[프로그래머스/JavaScript] 배달 (Level 2)