-
[못풀었다/프로그래머스] 배달코딩테스트 2023. 5. 31. 11:33
function solution(N, road, K) { const dist = Array(N+1).fill(Infinity) const adj = Array.from({length:N+1},()=>[]) road.forEach((el)=>{ const [r1,r2,t] = el adj[r1].push({to:r2,time:t}) adj[r2].push({to:r1,time:t}) }) let queue = [{to:1,time:0}] dist[1] = 0; while(queue.length){ let {to,time} = queue.pop(); adj[to].forEach((next)=>{ if(dist[next.to]>dist[to]+next.time){ dist[next.to] = dist[to]+next.time queue.push(next) } }) } return dist.filter((el)=>el<=K).length }
'코딩테스트' 카테고리의 다른 글
[못풀었다/꼭다시풀기/프로그래머스] 가장 큰 정사각형찾기 (0) 2023.06.04 [못풀었다/프로그래머스] 하노이의 탑 (0) 2023.06.03 [못풀었다/프로그래머스/js] 멀쩡한 사각형 (0) 2023.05.18 코딩테스트시 주의해야할 사항 (0) 2023.05.09 [프로그래머스] 수식최대화 (0) 2023.05.03