https://www.acmicpc.net/problem/2617코드from collections import dequeimport sysinput = sys.stdin.readlineINF = int(1e9)n, m = map(int, input().split())bigger = [[] for _ in range(n+1)]smaller = [[] for _ in range(n+1)]for _ in range(m): a, b = map(int, input().split()) bigger[b].append(a) smaller[a].append(b)def bfs(start, graph): cnt = 0 visited = [False]*(n+1) q = deque([start]..
문제풀이/DFS_BFS
https://www.acmicpc.net/problem/17086코드from collections import dequeimport sysinput = sys.stdin.readlinen, m = map(int, input().split())map_data = [list(map(int, input().split())) for _ in range(n)]dir = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]def bfs(x, y): visited = [[False]*m for _ in range(n)] visited[x][y] = True q = deque([(x, y, 0)]) while q: ..
https://www.acmicpc.net/problem/16932코드from collections import dequeimport sysinput = sys.stdin.readlinen, m = map(int, input().split())matrix = [list(map(int, input().split())) for _ in range(n)]dx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]def bfs(x, y, group_num): res = 1 q = deque([(x, y)]) matrix[x][y] = group_num while q: now_x, now_y = q.popleft() for i in range(4): ..
https://www.acmicpc.net/problem/1707 코드from collections import dequeimport sysinput = sys.stdin.readlinedef bfs(edges, start, colors): q = deque([start]) colors[start] = 1 while q: now = q.popleft() for nx in edges[now]: if colors[nx] == 0: colors[nx] = colors[now] % 2+1 q.append(nx) elif colors[nx] == colors[now]: ..

https://www.acmicpc.net/problem/2178코드const fs = require("fs");const filePath = process.platform === "linux" ? "dev/stdin" : "./input.txt";const input = fs.readFileSync(filePath).toString().trim().split("\n");class Node { constructor(value) { this.value = value; this.next = null; }}class Queue { constructor() { this.head = null; this.tail = null; this.size = 0; } push(value) ..