1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include<cstdio> int arr[102][102]; bool check[102][102]; int dx[]={0,0,1,-1}, dy[]={1,-1,0,0}; int n,m,k,r,c,temp,max; void trash(int x, int y) { check[x][y]=true; temp++; for(int k=0; k<4; k++) { int nx=x+dx[k]; int ny=y+dy[k]; if(1<=nx && nx<=n && 1<=ny && ny<=m) { if(arr[nx][ny]==1 && !check[nx][ny]) trash(nx,ny); } } } int main(void) { scanf("%d %d %d", &n, &m, &k); for(int i=0; i<k; i++){ scanf("%d %d", &r, &c); arr[r][c]=1; } for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { if(arr[i][j]==1 && !check[i][j]){ temp=0; trash(i,j); max=max>temp?max:temp; } } } printf("%d", max); return 0; } | cs |
ㅎㅏ 배열 가로세로 맨날 틀림ㅠ
'백준 2 > 그래프' 카테고리의 다른 글
| [백준 9466] 텀 프로젝트 (0) | 2020.12.08 |
|---|---|
| [백준 10026] 적록색약 (C++/Python) (0) | 2020.12.08 |
| [백준 2468] 안전영역 (C++/Python) (0) | 2020.12.08 |
| [백준 2583] 영역 구하기 (C++/Python) (0) | 2020.12.08 |
| [백준 1697] 숨바꼭질 (C++/Python) (0) | 2020.12.08 |