문제풀이/최단경로

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/1719코드import sysinput = sys.stdin.readlineINF = int(1e9)n, m = map(int, input().split())graph = [[INF]*(n+1) for _ in range(n+1)]path_table = [["-"]*(n+1) for _ in range(n+1)]for i in range(1, n+1): graph[i][i] = 0for _ in range(m): a, b, t = map(int, input().split()) graph[a][b] = t graph[b][a] = t path_table[a][b] = b path_table[b][a] = afor k ..
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)]..
https://www.acmicpc.net/problem/10282 코드from heapq import heappop, heappushimport sysinput = sys.stdin.readlinefor _ in range(int(input())): n, d, c = map(int, input().split()) graph = [[] for _ in range(n+1)] for _ in range(d): a, b, s = map(int, input().split()) heappush(graph[b], (s, a)) # Dijkstra dist = [int(1e9)] * (n+1) dist[c] = 0 hq = [(0, c)] while..
딜레이레이
'문제풀이/최단경로' 카테고리의 글 목록