Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include <iostream>
- #define runrunrun ios_base::sync_with_stdio(false),cin.tie(0);
- bool chart[1010][1010];
- void dfs(int i,int j){
- chart[i][j] = false;
- if (chart[i-1][j]){
- dfs (i-1,j);
- }
- if (chart[i][j+1]){
- dfs (i,j+1);
- }
- if (chart[i][j-1]){
- dfs (i,j-1);
- }
- if (chart[i+1][j]){
- dfs (i+1,j);
- }
- }
- int main(){
- int m,n;
- int t;
- runrunrun
- for(cin >> t;t--;){
- cin >> m >> n;
- int chunkC = 0;
- for (int i=0;i<1010;++i){
- for (int j=0;j<1010;++j)
- chart[i][j] = false;
- }
- for (int i=1;i<=m;++i){
- string input;
- cin >> input;
- for (int j=1;j<=n;++j){
- chart[i][j] = input[j-1] == '.';
- }
- }
- for (int i=1;i<=m;++i){
- for (int j=1;j<=n;++j){
- if (chart[i][j]){
- dfs (i,j);
- ++chunkC;
- }
- }
- }
- cout << chunkC << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement