From 5c1da829e6717cd8885a01dfe3f7c99111769dd1 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 25 May 2026 01:54:08 +0900 Subject: [PATCH] =?UTF-8?q?1012=20=EC=9C=A0=EA=B8=B0=EB=86=8D=EB=B0=B0?= =?UTF-8?q?=EC=B6=94=20:=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week2/BOJ1012/BOJ1012_V1.cpp | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/week2/BOJ1012/BOJ1012_V1.cpp diff --git a/src/week2/BOJ1012/BOJ1012_V1.cpp b/src/week2/BOJ1012/BOJ1012_V1.cpp new file mode 100644 index 0000000..b791118 --- /dev/null +++ b/src/week2/BOJ1012/BOJ1012_V1.cpp @@ -0,0 +1,63 @@ +#include +using namespace std; +int T,M,N,K; +vector> farm; +vector> visited; +int dy[4] = {-1, 0, 1, 0}; +int dx[4] = {0, 1, 0, -1}; + +void dfs(int y, int x) { + visited[y][x] = 1; + + for (int i = 0; i < 4; i++) { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny >= M || ny < 0 || nx >= N || nx < 0 || visited[ny][nx] || !farm[ny][nx]) continue; + + dfs(ny, nx); + } +} + +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + + cin >> T; + + for (int n = 0; n < T; n++) { + cin >> M >> N >> K; + int cnt = 0; + for (int i=0; i(N, 0)); + visited.push_back(vector(N, 0)); + } + for (int i = 0; i < K; i++) { + int y,x; + cin >> y >> x; + farm[y][x] = 1; + } + + for(int i=0; i