Language: C++

#include<cfloat>
#include<cstring>
#define foreach(t,p,it) for(t::iterator it=p.begin(),it!=p.end(),++it)
#define all(p) p.begin(),p.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
using namespace std;

const int W=210,H = 210;
int block[W][H];
int ans;

int w,h,xs,ys,xg,yg,n,c,d,x,y;
void solve(int xi,int yi)
{
    if(ans == 1) return ;
    //cout << xi <<" " << yi << endl;
    if(xi==xg && yi==yg){ ans = 1; return;}
    if(block[xi][yi] == c)
    {
        block[xi][yi] = 0;
        solve(xi-1,yi);
        solve(xi,yi-1);
        solve(xi+1,yi);
        solve(xi,yi+1);
    }
    else return;
}

int main()
{
    while(cin >> w >> h )
    {
        if(w==0 && h==0) break;
        memset(block,0,sizeof(block));
        ans = 0;
        cin >> xs >> ys;
        cin >> xg >> yg;
        cin >> n;
        REP(n)
        {
            cin >> c >> d >> x >> y;
            //cout << x << ","<< y << endl;
            if(d==1) //tate
            {
                block[x][y] = c;
                block[x][y+1] =c;
                block[x][y+2] = c;
                block[x][y+3] = c;
                block[x+1][y] = c;
                block[x+1][y+1] = c;
                block[x+1][y+2] = c;
                block[x+1][y+3] = c;
            }
            else
            {
                block[x][y] = c;
                block[x+1][y] = c;
                block[x+2][y] = c;
                block[x+3][y] = c;
                block[x][y+1] = c;
                block[x+1][y+1] = c;
                block[x+2][y+1] = c;
                block[x+3][y+1] = c;
            }
        }
        c = block[xs][ys];
        if(c==0) {cout <<"NG" << endl; continue;}
        
        //cout << xs << " " << ys << " " << c << endl;
        //cout <<"input " << endl;
        solve(xs,ys);

        if(ans) cout << "OK" << endl;
        else cout << "NG" << endl;

    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:11: error: 'cin' was not declared in this scope
   32 |     while(cin >> w >> h )
      |           ^~~
a.cc:3:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    2 | #include<cstring>
  +++ |+#include <iostream>
    3 | #define foreach(t,p,it) for(t::iterator it=p.begin(),it!=p.end(),++it)
a.cc:68:19: error: 'cout' was not declared in this scope
   68 |         if(c==0) {cout <<"NG" << endl; continue;}
      |                   ^~~~
a.cc:68:19: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:68:34: error: 'endl' was not declared in this scope
   68 |         if(c==0) {cout <<"NG" << endl; continue;}
      |                                  ^~~~
a.cc:3:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    2 | #include<cstring>
  +++ |+#include <ostream>
    3 | #define foreach(t,p,it) for(t::iterator it=p.begin(),it!=p.end(),++it)
a.cc:74:17: error: 'cout' was not declared in this scope
   74 |         if(ans) cout << "OK" << endl;
      |                 ^~~~
a.cc:74:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:74:33: error: 'endl' was not declared in this scope
   74 |         if(ans) cout << "OK" << endl;
      |                                 ^~~~
a.cc:74:33: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:75:14: error: 'cout' was not declared in this scope
   75 |         else cout << "NG" << endl;
      |              ^~~~
a.cc:75:14: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:75:30: error: 'endl' was not declared in this scope
   75 |         else cout << "NG" << endl;
      |                              ^~~~
a.cc:75:30: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'