File tree 1 file changed +52
-0
lines changed
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+
4
+ using namespace std ;
5
+
6
+ bool arr[50 + 2 ][50 + 2 ] = {0 , };
7
+
8
+ int answer = 0 ;
9
+
10
+ void dfs (int row, int col, bool isStart){ // isStart -> 맨 처음 0
11
+ if (arr[col][row] == 0 ) return ;
12
+ else {
13
+ arr[col][row] = 0 ;
14
+ dfs (row, col - 1 , 0 );
15
+ dfs (row, col + 1 , 0 );
16
+ dfs (row - 1 , col, 0 );
17
+ dfs (row + 1 , col, 0 );
18
+ if (isStart) answer++;
19
+ }
20
+
21
+ }
22
+
23
+ int main (void ){
24
+ ios_base::sync_with_stdio (false ); cin.tie (NULL );
25
+
26
+ int T;
27
+ cin >> T;
28
+
29
+ while (T--){
30
+ int M, N, K;
31
+ cin >> M >> N >> K;
32
+
33
+ // vector<vector<bool>> v(M, vector<bool>(N, 0));
34
+ vector<pair<int , int >> v; // 배추 위치 저장 벡터
35
+
36
+ for (int i = 0 ; i < K; i++){
37
+ int row, col = 0 ;
38
+ cin >> row >> col;
39
+ v.push_back (make_pair (row + 1 , col + 1 ));
40
+ arr[col + 1 ][row + 1 ] = 1 ;
41
+ }
42
+
43
+ for (int i = 0 ; i < v.size (); i++){
44
+ dfs (v[i].first , v[i].second , 1 );
45
+ }
46
+
47
+ cout << answer << ' \n ' ;
48
+ answer = 0 ;
49
+ }
50
+
51
+ return 0 ;
52
+ }
You can’t perform that action at this time.
0 commit comments