다익스트라

https://school.programmers.co.kr/learn/courses/30/lessons/132266코드 (BFS)function solution(n, roads, sources, destination) { const graph = Array.from(new Array(n + 1), () => []); for (const [a, b] of roads) { graph[a].push(b); graph[b].push(a); } const q = [destination]; const dist = new Array(n + 1).fill(Number.MAX_SAFE_INTEGER); dist[destination] = 0; while (q.length > 0) { cons..
https://www.acmicpc.net/problem/1916코드const fs = require("fs");const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt";const input = fs.readFileSync(filePath).toString().trim().split("\n");const n = +input[0];const m = +input[1];const path = Array.from(new Array(n + 1), () => new Array(n + 1).fill(Infinity));for (let i = 1; i +item); if (path[start][end] > cost) { path..
https://www.acmicpc.net/problem/1261코드 (BFS)from collections import dequem, n = map(int, input().split())maze = [input() for _ in range(n)]dx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]break_num = [[n*m]*m for _ in range(n)]break_num[0][0] = 0q = deque([(0, 0)])while q: x, y = q.popleft() for i in range(4): nx = x+dx[i] ny = y+dy[i] if 0 cnt: break_num[nx][ny] = ..
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15QRX6APsCFAYD&categoryId=AV15QRX6APsCFAYD&categoryType=CODE&problemTitle=&orderBy=RECOMMEND_COUNT&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=2 코드from heapq import heappop, heappushdx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]for tc in range(1, int(input())+1): n = int(input()) board = [input() for _ in range(n)]..
17396번: 백도어 첫 번째 줄에 분기점의 수와 분기점들을 잇는 길의 수를 의미하는 두 자연수 N과 M이 공백으로 구분되어 주어진다.(1 ≤ N ≤ 100,000, 1 ≤ M ≤ 300,000) 두 번째 줄에 각 분기점이 적의 시야에 보이는 www.acmicpc.net 코드 from heapq import heappop, heappush import sys input = sys.stdin.readline INF = sys.maxsize n, m = map(int, input().split()) visible = list(map(int, input().split())) visible[n-1] = 0 graph = [[] for _ in range(n)] for _ in range(m): a, b, t =..
딜레이레이
'다익스트라' 태그의 글 목록