Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to;     // 辺の行き先
  int weight; // 辺の重み
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprep(i, j, h, w) rep(i, h) rep(j, w)
#define rrep(i, m, n) for (int i = m; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define aall(x, n) (x).begin(), (x).begin() + (n)
#define VEC(type, name, n)                                                     \
  std::vector<type> a(n);                                                      \
  rep(i, n) std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed << setprecision
#define vvector(name, typ, m, n, a)                                            \
  vector<vector<typ>> name(m, vector<typ>(n, a))
#define vvvector(name, t, l, m, n, a)                                          \
  vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<int>(n, a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
long ggd(long a, long b) { // 最小公倍数，最大公約数
  if (a < b)
    swap(a, b);
  if (b == 0) {
    return a;
  }
  return ggd(b, a % b);
}
int main() {
  int h, w;
  std::cin >> h >> w;
  vvector(a, int, h, w, 0);
  reprep(i, j, h, w) std::cin >> a[i][j];
  std::vector<int> q, ww, e, r;
  rep(i, h) {
    rep(j, w) {
      if (a[i][j] % 2 == 1) {
        a[i][j + 1]++;
        q.pb(i + 1);
        ww.pb(j + 1);
        e.pb(i + 1);
        r.pb(j + 2);
      }
    }
  }
  rep(i, h - 1) {
    if (a[i][w - 1] % 2 == 1) {
      a[i + 1][w - 1]++;
      q.pb(i + 1);
      ww.pb(w);
      e.pb(i + 2);
      r.pb(w);
    }
  }
  std::cout << q.size() << std::endl;
  rep(i, q.size()) {
    std::cout << q[i] << ' ' << ww[i] << ' ' << e[i] << ' ' << r[i]
              << std::endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to;     // 辺の行き先
  int weight; // 辺の重み
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprep(i, j, h, w) rep(i, h) rep(j, w)
#define rrep(i, m, n) for (int i = m; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define aall(x, n) (x).begin(), (x).begin() + (n)
#define VEC(type, name, n)                                                     \
  std::vector<type> a(n);                                                      \
  rep(i, n) std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed << setprecision
#define vvector(name, typ, m, n, a)                                            \
  vector<vector<typ>> name(m, vector<typ>(n, a))
#define vvvector(name, t, l, m, n, a)                                          \
  vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<int>(n, a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
long ggd(long a, long b) { // 最小公倍数，最大公約数
  if (a < b)
    swap(a, b);
  if (b == 0) {
    return a;
  }
  return ggd(b, a % b);
}
int main() {
  int h, w;
  std::cin >> h >> w;
  vvector(a, int, h, w, 0);
  reprep(i, j, h, w) std::cin >> a[i][j];
  std::vector<int> q, ww, e, r;
  rep(i, h) {
    rep(j, w - 1) {
      if (a[i][j] % 2 == 1) {
        a[i][j + 1]++;
        q.pb(i + 1);
        ww.pb(j + 1);
        e.pb(i + 1);
        r.pb(j + 2);
      }
    }
  }
  rep(i, h - 1) {
    if (a[i][w - 1] % 2 == 1) {
      a[i + 1][w - 1]++;
      q.pb(i + 1);
      ww.pb(w);
      e.pb(i + 2);
      r.pb(w);
    }
  }
  std::cout << q.size() << std::endl;
  rep(i, q.size()) {
    std::cout << q[i] << ' ' << ww[i] << ' ' << e[i] << ' ' << r[i]
              << std::endl;
  }
}