For this Question: A group of connected 1's forms an island. The task is to print the number of islands present. We have a boolean matrix A of size NxM.
Note: if two vertices are diagonally connected they belong to the same connected componentThe first line contains two space separated integers N and M. Then in the next line are the NxM inputs of the matrix A separated by space.

Constraints:
1 <= N, M <= 100
0 <= A[i][j] <= 1For each testcase in a new line, print the number of islands present.Input
3 3
1 1 0 0 0 1 1 0 1

Output
2

Input
4 4
1 1 0 0 0 0 1 0 0 0 0 1 0 1 0 0

Output
2

Explanation:
Testcase 1: The graph will look like
1 1 0
0 0 1
1 0 1
Here, two islands will be formed
First island will be formed by elements {A[0][0] ,  A[0][1], A[1][2], A[2][2]}
Second island will be formed by {A[2][0]}., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;

#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
int x[8]={1,-1,0,0,1,1,-1,-1};
int y[8]={0,0,1,-1,-1,1,1,-1};
int n,m;
int check(int x,int y)
{

	if(x>=0 && x<n && y>=0 && y<m) return 1;
	else return 0;
}

int vis[2000][2000];
int A[2000][2000];
void dfs(int a,int b)
{   vis[a][b]=1;
	for(int i=0;i<8;i++)
	{
       int aa=a+x[i],bb=b+y[i];
       if(check(aa,bb)==1 && vis[aa][bb]==0 && A[aa][bb]==1)
       {
       	dfs(aa,bb);
       }
	}
}
signed main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif

		
		cin>>n>>m;
		
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
                   cin>>A[i][j];
			}
		}
          int cnt=0;
			for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
                   if(vis[i][j]==0 && A[i][j]==1)
                   { cnt++;
                   	dfs(i,j);
                   }
			}
		}
		cout<<cnt<<endl;

	
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?