Untitled
unknown
c_cpp
3 years ago
622 B
11
Indexable
#include <bits/stdc++.h> #define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl "\n" using namespace std; int a[107][107],n,m,color=0; void init(){ for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j]; } void dfs(int r,int c){ a[r][c]=color; if(a[r][c-1]==-1 && c>1) dfs(???,???-???); if(a[???][???+???]==-1 && c<m) dfs(r,c+1); if(a[r-???][c]==-1 && r>1) dfs(???-1,???); if(a[???+1][???]==-1 && r<n) dfs(r+???,c); } int main() {_ cin>>n>>m; init(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(a[i][j]==-1){ color++; dfs(i,j); } cout<<color; }
Editor is loading...