Advertisement
Saleh127

UVA 871

Jun 22nd, 2021
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define ll long long
  5. string a[200],b;
  6. bool v[200][200];
  7. ll n,m,ans=0;
  8. bool check(ll i,ll j)
  9. {
  10. if(i<0 || j<0 || i>=n || j>=m || v[i][j]==1 || a[i][j]=='0') return 0;
  11. return 1;
  12. }
  13.  
  14. void dfs(ll i,ll j)
  15. {
  16. v[i][j]=1;
  17. ans++;
  18.  
  19. if(check(i,j+1)) dfs(i,j+1);
  20. if(check(i,j-1)) dfs(i,j-1);
  21. if(check(i+1,j)) dfs(i+1,j);
  22. if(check(i-1,j)) dfs(i-1,j);
  23. if(check(i+1,j-1)) dfs(i+1,j-1);
  24. if(check(i-1,j-1)) dfs(i-1,j-1);
  25. if(check(i+1,j+1)) dfs(i+1,j+1);
  26. if(check(i-1,j+1)) dfs(i-1,j+1);
  27.  
  28. }
  29. int main()
  30. {
  31. ios_base::sync_with_stdio(0);
  32. cin.tie(0);
  33. cout.tie(0);
  34.  
  35.  
  36.  
  37. int t;
  38. cin>>t;
  39.  
  40. getline(cin,b);
  41. getline(cin,b);
  42.  
  43. for(int cs=1; cs<=t; cs++)
  44. {
  45.  
  46. ll i,j,k,l;
  47.  
  48. n=m=0;
  49.  
  50. while(getline(cin,b))
  51. {
  52. if(b.size()==0) break;
  53. a[n++]=b;
  54. }
  55. m=a[0].size();
  56.  
  57. l=0;
  58.  
  59. for(i=0; i<n; i++)
  60. {
  61. for(j=0; a[i][j]; j++)
  62. {
  63. if(a[i][j]=='1')
  64. {
  65. dfs(i,j);
  66. l=max(l,ans);
  67. ans=0;
  68. }
  69. }
  70.  
  71. }
  72.  
  73. cout<<l<<endl;
  74. if(cs<t) cout<<endl;
  75.  
  76. memset(v,0,sizeof v);
  77.  
  78. }
  79.  
  80. return 0;
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement