유기농 배추와 99% 동일한 문제이다.
x,y만 조심하면 된다 r:y, c:x에 해당한다. board[y][x]이다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
using namespace std;
#define endl "\n"
#define MAX 100+1
int n, m, k;
bool board[MAX][MAX];
bool visited[MAX][MAX];
int isMax;
int ans;
int dy[] = { 0,0,-1,1 };
int dx[] = { 1,-1,0,0 };
void dfs(int y, int x) {
visited[y][x] = true;
isMax++;
for (int i = 0; i < 4; i++)
{
int nx = dx[i] + x;
int ny = dy[i] + y;
if (nx < 1 || nx > m || ny < 1 || ny > n)
{
continue;
}
if (board[ny][nx] && !visited[ny][nx])
{
dfs(ny, nx);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
//ifstream cin; cin.open("input.txt");
cin >> n >> m >> k;
while (k--)
{
int x, y;
cin >> y >> x;
board[y][x] = true;
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (board[i][j] && !visited[i][j])
{
isMax = 0;
dfs(i, j);
if (ans < isMax)
{
ans = isMax;
}
}
}
}
cout << ans;
}
https://scarlettb.tistory.com/96 // x,y 변수 참고