[백준] 7576번: 토마토 (JavaScript)
·
PS
문제https://www.acmicpc.net/problem/7576  개념그래프 탐색BFS 구현 코드(JavaScript)const fs = require('fs');const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');const [m, n] = input[0].split(' ').map(Number);const tomatoes = input.slice(1).map((row) => row.split(' ').map(Number));let q = [];const dx = [1, -1, 0, 0];const dy = [0, 0, 1, -1];let day = 0;for (let i = 0; i = n || ny = m) cont..
[백준] 1062번: 연결 요수의 개수 (JavaScript)
·
PS
문제https://www.acmicpc.net/problem/11724개념그래프 탐색DFS, BFS구현 코드(JavaScript)const fs = require('fs');let input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');const [n, m] = input[0].split(' ').map(Number);const graph = Array(n + 1) .fill(0) .map(() => Array(n + 1).fill(0));for (let i = 1; i { const queue = [start]; visited[start] = true; while (queue.length) { const node = qu..
[백준] 2178번: 미로 탐색
·
PS
문제https://www.acmicpc.net/problem/2178  개념그래프, BFS  실행 결과     구현 코드(c++)#include #include using namespace std;int n, m;int arr[100][100]; // 미로 배열int dist[100][100]; // 최단 거리 배열int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // 미로의 크기 입력 cin >> n >> m; // dx,dy: 상, 우, 하, 좌 방향 벡터 int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; // 미로 입력 받기 (행->렬) for (int i = 0; ..
[백준] 1260번: DFS와 BFS
·
PS
문제https://www.acmicpc.net/problem/1260  개념그래프, DFS, BFS  실행 결과     구현 코드(c++)#include #include #include #include using namespace std;vector> graph; // 2차원 벡터로 선언vector visited; // 방문 처리용 배열 선언// 깊이 우선 탐색: 스택 재귀void dfs(int x) { visited[x] = true; cout q; visited[start] = true; // 현재 노드 방문 처리 q.push(start); // 넣기 while (!q.empty()) { int x = q.front(); // 가장 먼저 들어온 원소 확인 q.pop(); // ..