Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //============================================================================
- // Name : ACM
- // Author : Tarango Khan
- // Team : BRACU Byteheads
- //============================================================================
- #include <bits/stdc++.h>
- using namespace std;
- #define Size 100005
- #define Max 9999999
- struct pos{
- int r;
- int c;
- pos(int a,int b){
- r = a;
- c = b;
- }
- };
- int row, col;
- char G[505][505];
- int taken[505][505];
- bool visited[505][505];
- int dx[] = {1,-1,0,0};
- int dy[] = {0,0,1,-1};
- int sr, sc, tr, tc;
- int isValid(int r, int c) {
- if (r <= 0 || c <= 0 || r > row || c > col)
- return false;
- return true;
- }
- bool call() {
- pos p(sr, sc);
- visited[sr][sc] = true;
- queue<pos> Q;
- Q.push(p);
- int rr, cc;
- while (Q.empty() == false) {
- pos cur = Q.front();
- Q.pop();
- //printf("Cur r: %d , c: %d\n",cur.r,cur.c);
- if (cur.r == tr && cur.c == tc) {
- return true;
- }
- for(int i = 0;i<4;i++){
- rr = cur.r + dx[i];
- cc = cur.c + dy[i];
- if (isValid(rr, cc) == true && visited[rr][cc] == false) {
- if(G[rr][cc] == '.' || taken[rr][cc] >= 1){
- G[rr][cc] = '.';
- visited[rr][cc] = true;
- pos p(rr,cc);
- Q.push(p);
- }
- if(G[rr][cc] == '*'){
- taken[rr][cc]++;
- }
- }
- }
- }
- return false;
- }
- int main() {
- string s;
- int nCase;
- //scanf("%d", &nCase);
- cin >> nCase;
- for (int cs = 1; cs <= nCase; cs++) {
- //scanf("%d %d", &row, &col);
- cin >> row >> col;
- for (int i = 0; i < row; i++) {
- cin >> s;
- for (int j = 0; j < col; j++) {
- G[i+1][j+1] = s[j];
- }
- }
- //scanf("%d %d %d %d", &sr, &sc, &tr, &tc);
- cin >> sr >> sc >> tr >> tc;
- //printf("sr: %d , sc: %d\n",sr,sc);
- memset(taken,0,sizeof(taken));
- memset(visited,false,sizeof(visited));
- //printf("Taken Input\n");
- bool res = call();
- if(res == true) printf("YES\n");
- else printf("NO\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment