백준 토마토 성공!! 1068번 BFS


백준 토마토 성공!! 1068번 BFS

#include<stdio.h> int map[1001][1001] = { -1 }; int cue[1100000] = { 0 }; void bfs(int length,int width) { int count = 0; int front = 0; int rear = 0; int pop; for (int i = 0; i < length; i++) { for (int j = 0; j < width; j++) { if (map[i][j] == 1) cue[rear++] = i * width + j; } } int first = rear; while (front <= rear) { pop = cue[front++]; int y = pop / width; int x = pop % width; if (y + 1 < length && map[y + 1][x] == 0) { cue[rear++]=pop + width; map[y + 1][x] = map[y][x]+1; } if (0 < y && m...



원문링크 : 백준 토마토 성공!! 1068번 BFS