-
Notifications
You must be signed in to change notification settings - Fork 0
/
cses1192.cpp
48 lines (43 loc) · 880 Bytes
/
cses1192.cpp
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
40
41
42
43
44
45
46
47
48
#include<bits/stdc++.h>
using namespace std;
#define int long long
bool went[1005][1005];
bool San[1005][1005];
void DFS (int i, int j)
{
went[i][j] = true;
if (San[i + 1][j] == true && went[i + 1][j] == false) DFS(i+1,j);
if (San[i - 1][j] == true && went[i - 1][j] == false) DFS(i-1,j);
if (San[i][j + 1] == true && went[i][j + 1] == false) DFS(i,j+1);
if (San[i][j - 1] == true && went[i][j - 1] == false) DFS(i,j-1);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
char c;
cin >> c;
if (c == '.') San[i][j] = true;
}
}
int res = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (San[i][j] == true && went[i][j] == false)
{
res++;
DFS(i,j);
}
}
}
cout << res;
}