alexjercan/bugnet huggingface dataset:
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>

int field[102][102]; // y,x
bool flag;
int sx, sy, gx, gy, col;
std::map<int, bool> memo;

void erase() {
  for (int i = 0; i < 102; i++)
    for (int j = 0; j < 102; j++)
      field[i][j] = 0;
}

void DFS(int x, int y) {
  if (field[y][x] != col || memo[1000 * x + y])
    return;
  if (x == gx && y == gy) {
    flag = true;
    return;
  }
  memo[1000 * x + y] = true;
  DFS(x + 1, y);
  if (flag)
    return;
  DFS(x, y + 1);
  if (flag)
    return;
  DFS(x - 1, y);
  if (flag)
    return;
  DFS(x, y - 1);
}

int main() {
  int n, c, d, bx, by;
  while (true) {
    flag = false;
    erase();
    memo.clear();

    std::cin >> c >> d;
    if (!c && !d)
      return 0;

    std::cin >> sx >> sy;
    std::cin >> gx >> gy;

    std::cin >> n;
    for (int i = 0; i < n; i++) {
      std::cin >> c >> d >> bx >> by;
      if (d == 0)
        for (int h = by; h < by + 2; h++)
          for (int w = bx; w < bx + 4; w++)
            field[h][w] = c;
      else
        for (int h = by; h < by + 4; h++)
          for (int w = bx; w < bx + 2; w++)
            field[h][w] = c;
    }

    col = field[gy][gx];
    DFS(sx, sy);
    if (flag)
      std::cout << "OK\\n";
    else
      std::cout << "NG\\n";
  }
}

Error: 0

Fixed submission:

#include <iostream>

int field[102][102]; // y,x
bool flag;
int sx, sy, gx, gy, col;

void erase() {
  for (int i = 0; i < 102; i++)
    for (int j = 0; j < 102; j++)
      field[i][j] = 0;
}
void DFSr(int x, int y) {
  if (field[y][x] != col)
    return;
  if (x == gx && y == gy) {
    flag = true;
    return;
  }
  DFSr(x + 1, y);
  if (flag)
    return;
  DFSr(x, y + 1);
  if (flag)
    return;
  DFSr(x, y - 1);
  if (flag)
    return;
  DFSr(x - 1, y);
}

void DFSl(int x, int y) {
  if (field[y][x] != col)
    return;
  if (x == gx && y == gy) {
    flag = true;
    return;
  }
  DFSl(x - 1, y);
  if (flag)
    return;
  DFSl(x, y + 1);
  if (flag)
    return;
  DFSl(x, y - 1);
  if (flag)
    return;
  DFSl(x + 1, y);
}

void DFS(int x, int y) {
  if (sx < gy)
    DFSr(x, y);
  else
    DFSl(x, y);
}

int main() {
  int n, c, d, bx, by;
  while (true) {
    flag = false;
    erase();

    std::cin >> c >> d;
    if (!c && !d)
      return 0;

    std::cin >> sx >> sy;
    std::cin >> gx >> gy;

    std::cin >> n;
    for (int i = 0; i < n; i++) {
      std::cin >> c >> d >> bx >> by;
      if (d == 0)
        for (int h = by; h < by + 2; h++)
          for (int w = bx; w < bx + 4; w++)
            field[h][w] = c;
      else
        for (int h = by; h < by + 4; h++)
          for (int w = bx; w < bx + 2; w++)
            field[h][w] = c;
    }

    col = field[gy][gx];
    DFS(sx, sy);
    if (flag)
      std::cout << "OK\\n";
    else
      std::cout << "NG\\n";
  }
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;

int w, h;
int field[102][102];
int sx, sy;
int gx, gy;
int n;
int color;
bool ans;

void DFS(int x, int y) {
  if (x == gx && y == gy) {
    ans = true;
    return;
  }
  if (field[y][x] == -1)
    return;
  field[y][x] = -1;
  if (color == field[y][x - 1])
    DFS(x - 1, y);
  if (color == field[y][x + 1])
    DFS(x + 1, y);
  if (color == field[y - 1][x])
    DFS(x, y - 1);
  if (color == field[y + 1][x])
    DFS(x, y + 1);
}
int main() {
  while (cin >> w >> h) {
    if (!w && !h)
      break;
    ans = false;
    memset(field, -1, sizeof(field));
    cin >> sx >> sy;
    cin >> gx >> gy;
    cin >> n;
    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      if (d == 1) {
        for (int i = 0; i < 4; i++) {
          for (int j = 0; j < 2; j++) {
            field[y + i][x + j] = c;
          }
        }
      } else if (d == 0) {
        for (int i = 0; i < 2; i++) {
          for (int j = 0; j < 4; j++) {
            field[y + i][x + j] = c;
          }
        }
      }
    }
    color = field[sy][sx];
    DFS(sx, sy);
    if (ans)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int w, h;
int field[101][101];
int gx, gy;
int sc;
void init() {
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      field[i][j] = 0;
    }
  }
}
bool search(int x, int y) {
  bool flag = false;
  if (x == gx && y == gy)
    flag = true;
  else {
    int vectorx[4] = {-1, 0, 1, 0}, vectory[4] = {0, -1, 0, 1};
    for (int i = 0; i < 4; i++) {
      if (x + vectorx[i] >= 0 && y + vectory[i] >= 0 && x + vectorx[i] < w &&
          y + vectory[i] < h) {
        if (field[x + vectorx[i]][y + vectory[i]] == sc) {
          field[x][y] = 0;
          flag |= search(x + vectorx[i], y + vectory[i]);
        }
      }
    }
  }
  return flag;
}
int main() {
  while (cin >> w >> h) {
    if (w == 0 && h == 0)
      break;
    int sx, sy;
    cin >> sx >> sy;
    cin >> gx >> gy;
    int n, c, x, y;
    bool d;
    init();
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> x >> y;
      int vectorx, vectory;
      if (d == 0) {
        vectorx = 4;
        vectory = 2;
      } else {
        vectorx = 2;
        vectory = 4;
      }
      for (int j = 0; j < vectorx; j++) {
        for (int k = 0; k < vectory; k++) {
          field[x + j][y + k] = c;
        }
      }
    }
    sc = field[sx][sy];
    if (search(sx, sy))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int F[102][102];

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y + 1, X, c);
  DFS(Y, X - 1, c);
}

int main() {
  int w, h, xs, ys, xg, yg, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;

    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        F[i][j] = 0;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }

    if (F[xs][ys] == 0) {
      cout << "NG" << endl;
    } else {
      DFS(xs, ys, F[xs][ys]);

      if (F[xg][yg] == -1) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
    }
  }
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[102][102];

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y + 1, X, c);
  DFS(Y, X - 1, c);
}

int main() {
  int w, h, xs, ys, xg, yg, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;

    for (int i = 0; i < 20; i++) {
      for (int j = 0; j < 20; j++) {
        F[i][j] = -1;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }

    if (F[xs][ys] == 0) {
      cout << "NG" << endl;
    } else {
      DFS(xs, ys, F[xs][ys]);

      if (F[xg][yg] == -1) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
    }
  }
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int F[102][102];
int xg, yg, w, h;

void DFS(int Y, int X, int c) {
  // if(Y < 1 || X < 1)
  // return;
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y + 1, X, c);
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y, X - 1, c);
}

int main() {
  int xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        F[i][j] = 10;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      if (c == 0)
        c = 1919810;
      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }
    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[102][102];
int xg, yg, w, h;

void DFS(int Y, int X, int c) {
  // if(Y < 1 || X < 1)
  // return;
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y + 1, X, c);
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y, X - 1, c);
}

int main() {
  int xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        F[i][j] = 0;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      if (c == 0)
        c = 1919810;
      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }
    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int C[102][102];

void meiro(int W, int H, int c) {
  if (C[W][H] != c) {
    return;
  }

  C[W][H] = -1;

  meiro(W + 1, H, c);
  meiro(W - 1, H, c);
  meiro(W, H + 1, c);
  meiro(W, H - 1, c);
}

int main() {
  while (1) {
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) {
      break;
    }

    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        C[i][j] = 10;
      }
    }

    int xs, ys, xg, yg;
    cin >> xs >> ys >> xg >> yg;

    int n;
    cin >> n;

    int c, d, x, y;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = x; j < x + 4; j++) {
          for (int k = y; k < y + 2; k++) {
            C[j][k] = c;
          }
        }
      } else {
        for (int j = x; j < x + 2; j++) {
          for (int k = y; k < y + 4; k++) {
            C[j][k] = c;
          }
        }
      }
    }

    meiro(xs, ys, C[xs][ys]);

    if (C[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }

  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int C[102][102];

void meiro(int W, int H, int c) {
  if (C[W][H] != c) {
    return;
  }

  C[W][H] = -1;

  meiro(W - 1, H, c);
  meiro(W, H + 1, c);
  meiro(W + 1, H, c);
  meiro(W, H - 1, c);
}

int main() {
  while (1) {
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) {
      break;
    }

    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        C[i][j] = 0;
      }
    }

    int xs, ys, xg, yg;
    cin >> xs >> ys >> xg >> yg;

    int n;
    cin >> n;

    int c, d, x, y;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = x; j < x + 4; j++) {
          for (int k = y; k < y + 2; k++) {
            C[j][k] = c;
          }
        }
      } else {
        for (int j = x; j < x + 2; j++) {
          for (int k = y; k < y + 4; k++) {
            C[j][k] = c;
          }
        }
      }
    }

    meiro(xs, ys, C[xs][ys]);

    if (C[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }

  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int C[102][102];

void meiro(int W, int H, int c) {
  if (C[W][H] != c) {
    return;
  }

  C[W][H] = -1;

  meiro(W - 1, H, c);
  meiro(W, H + 1, c);
  meiro(W + 1, H, c);
  meiro(W, H - 1, c);
}

int main() {
  while (1) {
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) {
      break;
    }

    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        C[i][j] = 10;
      }
    }

    int xs, ys, xg, yg;
    cin >> xs >> ys >> xg >> yg;

    int n;
    cin >> n;

    int c, d, x, y;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = x; j < x + 4; j++) {
          for (int k = y; k < y + 2; k++) {
            C[j][k] = c;
          }
        }
      } else {
        for (int j = x; j < x + 2; j++) {
          for (int k = y; k < y + 4; k++) {
            C[j][k] = c;
          }
        }
      }
    }

    meiro(xs, ys, C[xs][ys]);

    if (C[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }

  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[102][102];
int xg, yg, w, h;

void DFS(int Y, int X, int c) {
  if (Y < 1 || X < 1)
    // return;
    if (F[Y][X] != c) {
      return;
    }

  F[Y][X] = -1;
  DFS(Y + 1, X, c);
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y, X - 1, c);
}

int main() {
  int xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        F[i][j] = 0;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }
    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg, w, h;

void DFS(int Y, int X, int c) {
  if (Y < 1 || X < 1)
    return;
  if (F[Y][X] != c || Y > w || X > h) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y + 1, X, c);
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y, X - 1, c);
}

int main() {
  int xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 105; i++) {
      for (int j = 0; j < 105; j++) {
        F[i][j] = 0;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }
    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg, w, h;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c || Y > w || X > h) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y + 1, X, c);
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y, X - 1, c);
}

int main() {
  int xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 105; i++) {
      for (int j = 0; j < 105; j++) {
        F[i][j] = 0;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }
    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg, w, h;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y + 1, X, c);
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y, X - 1, c);
}

int main() {
  int xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        F[i][j] = 10;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }
    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg, w, h;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y + 1, X, c);
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y, X - 1, c);
}

int main() {
  int xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 105; i++) {
      for (int j = 0; j < 105; j++) {
        F[i][j] = 10;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }
    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg, w, h;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y + 1, X, c);
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y, X - 1, c);
}

int main() {
  int xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 105; i++) {
      for (int j = 0; j < 105; j++) {
        F[i][j] = 10;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }
    if (F[xs][ys] == 10) {
      cout << "NG" << endl;
      continue;
    }
    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg, w, h;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y + 1, X, c);
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y, X - 1, c);
}

int main() {
  int xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 105; i++) {
      for (int j = 0; j < 105; j++) {
        F[i][j] = 10;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }

    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -2000;
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y + 1, X, c);
  DFS(Y, X - 1, c);
}

int main() {
  int w, h, xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;

    cin >> xs >> ys >> xg >> yg >> n;
    int c[n], d[n], x[n], y[n], ca;
    for (int i = 0; i < n; i++) {
      cin >> c[i] >> d[i] >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++) {
      if (c[i] == 0) {
        ca = 1000;
        break;
      } else if (i == n - 1) {
        ca = 1000;
      }
    }
    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        F[i][j] = ca;
      }
    }
    for (int i = 0; i < n; i++) {
      if (d[i] == 0) {
        for (int j = 0; j < 4; j++) {
          F[x[i] + j][y[i]] = c[i];
          F[x[i] + j][y[i] + 1] = c[i];
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x[i]][y[i] + j] = c[i];
          F[x[i] + 1][y[i] + j] = c[i];
        }
      }
    }

    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -2000) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -2000;
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y + 1, X, c);
  DFS(Y, X - 1, c);
}

int main() {
  int w, h, xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;

    cin >> xs >> ys >> xg >> yg >> n;
    int c[n], d[n], x[n], y[n], ca;
    for (int i = 0; i < n; i++) {
      cin >> c[i] >> d[i] >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++) {
      if (c[i] == 0) {
        ca = 1000;
        break;
      } else if (i == n - 1) {
        ca = 0;
      }
    }
    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        F[i][j] = ca;
      }
    }
    for (int i = 0; i < n; i++) {
      if (d[i] == 0) {
        for (int j = 0; j < 4; j++) {
          F[x[i] + j][y[i]] = c[i];
          F[x[i] + j][y[i] + 1] = c[i];
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x[i]][y[i] + j] = c[i];
          F[x[i] + 1][y[i] + j] = c[i];
        }
      }
    }

    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -2000) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}