Laughing bomb

mail@pastecode.io avatar
unknown
plain_text
a year ago
953 B
2
Indexable
Never
#include <iostream>
using namespace std;

int in[102][102];
int Qx[100000];
int Qy[100000];
int r = -1, f = -1;
int dx[4]= {1,0,0,-1};
int dy[4]= {0,1,-1,0};
void push(int x, int y){
	r++;
	Qx[r] = x;
	Qy[r] = y;
}
void pop(int &x, int &y){
	f++;
	x = Qx[f];
	y = Qy[f];
}
int BFS(int x, int y){
	push(x,y);
	int t = 0;
	while(r != f){
		int r1 =r;
		int f1 =f;
		for(int i  = 0; i < r1 -f1 ; i++){
			pop(x,y);
			in[x][y] = 0;
		for(int j = 0; j < 4; j++ ){
			int x1 = x + dx[j];
			int y1 = y + dy[j];
			if(in[x1][y1] == 1){
				push(x1,y1);
			}
		}
		}
		t++;
	}
	return t;

}
int main(){
	freopen ("input.txt","r", stdin);
	int T;
	cin >> T;
	r = -1;
	f = -1;
	for(int tc = 1; tc <= 1; tc++){
		int n,m;
		int x,y;
		cin >> n >> m;
		for(int i = 1; i <= m; i++){
			for(int j = 1; j <= n; j++){
				cin >> in[i][j];
			}
		}
		cin >> x >> y;
		cout << BFS(x,y) << endl;
	}
	return 0;
}