https://school.programmers.co.kr/learn/courses/30/lessons/43164코드function solution(tickets) { let answer = []; const graph = new Map(); for (let i = 0; i a[1].localeCompare(b[1])); } const visited = new Array(tickets.length).fill(false); const dfs = (now, path) => { if (path.length === tickets.length + 1) { answer = [...path]; return; } if (answer.length > 0 || !graph.h..
문제풀이/DFS_BFS
https://school.programmers.co.kr/learn/courses/30/lessons/49189코드function solution(n, edge) { // 그래프 구성 const graph = Array.from(new Array(n + 1), () => new Array()); for (const e of edge) { graph[e[0]].push(e[1]); graph[e[1]].push(e[0]); } // BFS let farthest_dist = 0; let farthest_nodes = new Set(); const q = [[1, 0]]; const visited = new Array(n + 1).fill(false); visited[1] = ..
https://school.programmers.co.kr/learn/courses/30/lessons/43162코드3가지 버전으로 코드를 작성했다. 셋 다 정답 코드이다.양방향 큐를 이용한 BFSfunction solution(n, computers) { let answer = 0; const visited = new Array(n).fill(false); const bfs = (start)=>{ const q = [start]; visited[start] = true while(q.length>0){ const now = q.shift(); for(let i=0;i재귀를 이용한 DFSfunction solut..
https://www.acmicpc.net/problem/11967코드import sysfrom collections import deque, defaultdictinput = sys.stdin.readlinen, m = map(int, input().split())switchs = defaultdict(list)for _ in range(m): x, y, a, b = map(int, input().split()) switchs[(x, y)].append((a, b))dx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]q = deque([(1, 1)])# 불이 켜진 방 체크lights = [[False]*(n+1) for _ in range(n+1)]lights[1][1] = Tr..
https://www.acmicpc.net/problem/19238코드from collections import dequen, m, fuel = map(int, input().split())map_data = [[]]for _ in range(n): map_data.append([1]+list(map(int, input().split())))tx, ty = map(int, input().split())customers = [[-1, -1, -1, -1]]for i in range(1, m+1): sx, sy, ex, ey = map(int, input().split()) map_data[sx][sy] = -i customers.append([sx, sy, ex, ey])def get..