fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define F first
  6. #define S second
  7. #define ii pair < int , int >
  8. #define ever (;;)
  9.  
  10. const int N = 1010;
  11.  
  12. bool vis[N][N];
  13. int n,m,movex[4]={1,-1,0,0},movey[4]={0,0,1,-1};
  14. char a[N][N];
  15.  
  16. void dfs(int x,int y)
  17. {
  18. vis[x][y] = 1;
  19.  
  20. for(int i=0;i<4;i++)
  21. {
  22. int newx = x + movex[i];
  23. int newy = y + movey[i];
  24.  
  25. if( !vis[newx][newy] && a[newx][newy] == '.' )
  26. dfs(newx,newy);
  27. }
  28. }
  29.  
  30. int main()
  31. {
  32. cin>>n>>m;
  33. for(int i=1;i<=n;i++)
  34. for(int j=1;j<=m;j++)
  35. cin>>a[i][j];
  36.  
  37. for(int i=1;i<=n;i++)
  38. for(int j=1;j<=m;j++)
  39. if( !vis[i][j] && a[i][j] == '.' )
  40. dfs(i,j);
  41. }
  42.  
Success #stdin #stdout 0s 4280KB
stdin
Standard input is empty
stdout
Standard output is empty