Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int N = 1e3+5;
- int n, m, ans, ks, kb, xx, yy, x, y;
- bool used[N][N];
- int M[N][N];
- void dfs(int x, int y){
- if(x<0 || y<0 ||x>=n || y>=m || M[x][y] ==2|| used[x][y]){ return; }
- used[x][y] = 1;
- if(M[x][y]==1) --ans;
- for(int i = -1; i < 2; ++i){
- for(int j = -1; j < 2; ++j){
- if(i && j) continue;
- dfs(x+i,y+j);
- }
- }
- }
- int main(){
- ios_base::sync_with_stdio(0);
- cin.tie(0); cout.tie(0);
- cin >> n >> m >> ks >> kb >> xx >> yy;
- ans = kb;
- for(int i = 0; i < ks; ++i){
- cin >> x >> y;
- M[x][y] = 2;
- }
- for(int i = 0; i < kb; ++i){
- cin >> x >> y;
- M[x][y] = 1;
- }
- dfs(yy,xx);
- cout << ans;
- return 0;
- }
Add Comment
Please, Sign In to add comment